using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace RivercrabNet
{
    [ToolboxItem(true)]
    public class Rivercrab : ContainerControl
    {
        protected bool allowMoveShape;
        private bool _allowShowShapeMenu;
        protected Point BeginScrollPoint;
        protected string calenderScaleField;
        protected bool CheckVpFlag;
        private IContainer components;
        protected int CrossHairY = -1;
        protected int crossStopIndex;
        protected DataTable dataSource = new DataTable();
        protected Dictionary<int, ChartDiv> dicChartDiv = new Dictionary<int, ChartDiv>();
        protected bool drawCrossHairFlag;
        protected bool drawDragFrameFlag;
        private bool drawMenuFlag;
        protected bool drawMouseScrollFlag;
        protected bool drawPaintLineFlag;
        protected bool drawValuePanelFlag;
        protected int firstVisibleRecord;
        private Image _imgGraph;
        private List<BaseIndicator> _indList = new List<BaseIndicator>();
        private bool _isMultiSelect;
        protected bool isScrollByMouse;
        protected DateTime lastMouseMoveTime = DateTime.Now;
        protected bool lastRecordIsVisible;
        protected int lastVisibleRecord;
        protected string lastVisibleTimeKey = string.Empty;
        private int _leftYScaleWidth;
        protected bool lockGraph;
        private bool _loopFlag = true;
        protected Dictionary<RectangleF, BaseShape> ObjectRectDic = new Dictionary<RectangleF, BaseShape>();
        private OffSetMenu _offSetMenu = new OffSetMenu();
        protected ProcesBar processBarObject = new ProcesBar();
        private int _rightYScaleSpace;
        protected bool scrollAddSpeed;
        private bool _scrollCrossFlag;
        protected int scrollStep = 1;
        protected int selectState;
        internal PaintLineBase SelectedPaintLine;
        protected bool ShowCrossHair;
        private int _spaceRecord;
        protected object UpdateLock = new object();
        protected ChartDiv UserResizePanel;
        protected int VpIndex = -1;
        protected float xScaleSpace;
        private int _zoomType;

        public Rivercrab()
        {
            InitializeComponent();
            base.HandleCreated += ChartGraph_HandleCreated;
            base.SizeChanged += ChartGraph_SizeChanged;
            base.Paint += PicGraph_Paint;
            base.PreviewKeyDown += PicGraph_PreviewKeyDown;
            base.KeyUp += ChartGraph_KeyUp;
            base.MouseMove += ChartGraph_MouseMove;
            base.MouseUp += ChartGraph_MouseUp;
            base.MouseDown += ChartGraph_MouseDown;
            base.MouseWheel += ChartGraph_MouseWheel;
        }

        public bool AllowMoveShape
        {
            get { return allowMoveShape; }
            set { allowMoveShape = value; }
        }

        public bool AllowShowShapeMenu
        {
            get { return _allowShowShapeMenu; }
            set { _allowShowShapeMenu = value; }
        }

        public string CalenderScaleField
        {
            get { return calenderScaleField; }
        }

        [Browsable(false)]
        public int CrossStopIndex
        {
            get { return crossStopIndex; }
            set { crossStopIndex = value; }
        }

        public DataTable DataSource
        {
            get { return dataSource; }
        }

        [Browsable(false)]
        internal Dictionary<int, ChartDiv> DicChartDiv
        {
            get { return dicChartDiv; }
            set { dicChartDiv = value; }
        }

        [Browsable(false)]
        public int FirstVisibleRecord
        {
            get { return firstVisibleRecord; }
            set { firstVisibleRecord = value; }
        }

        [Browsable(false)]
        protected List<BaseIndicator> IndList
        {
            get { return _indList; }
            set { _indList = value; }
        }

        [Browsable(false)]
        public int LastVisibleRecord
        {
            get { return lastVisibleRecord; }
            set
            {
                lastVisibleRecord = value;
                if (lastVisibleRecord > dataSource.Rows.Count)
                {
                    lastVisibleRecord = dataSource.Rows.Count;
                }
                if (dataSource.Rows.Count > 0)
                {
                    lastVisibleTimeKey = dataSource.Rows[lastVisibleRecord - 1][calenderScaleField].ToString();
                    if (lastVisibleRecord == dataSource.Rows.Count)
                    {
                        lastRecordIsVisible = true;
                    }
                    else
                    {
                        lastRecordIsVisible = false;
                    }
                }
                else
                {
                    lastVisibleTimeKey = string.Empty;
                    lastRecordIsVisible = true;
                }
            }
        }

        public int LeftYScaleWidth
        {
            get { return _leftYScaleWidth; }
            set { _leftYScaleWidth = value; }
        }

        public bool LockGraph
        {
            get { return lockGraph; }
            set { lockGraph = value; }
        }

        public int RightYScaleSpace
        {
            get { return _rightYScaleSpace; }
            set { _rightYScaleSpace = value; }
        }

        public bool ScrollAddSpeed
        {
            get { return scrollAddSpeed; }
            set { scrollAddSpeed = value; }
        }

        [Browsable(true)]
        public float XScaleSpace
        {
            get { return xScaleSpace; }
            set { xScaleSpace = value; }
        }

        public int ZoomType
        {
            get { return _zoomType; }
            set { _zoomType = value; }
        }

        public BarShape AddBar(string name, int panelID)
        {
            if (((name != null) && !dataSource.Columns.Contains(name)) && dicChartDiv.ContainsKey(panelID))
            {
                var div = dicChartDiv[panelID];
                var shape = new BarShape
                                {
                                    Up_LineColor = Color.Lime,
                                    Down_lineColor = Color.Lime
                                };
                div.YScaleField.Add(name);
                shape.Name = name;
                shape.ShapeType = ShapeType.Bar;
                shape.DisplayName = name;
                div.ShapeDic.Add(name, shape);
                var column = new DataColumn(name);
                dataSource.Columns.Add(column);
                dataSource.Columns.Add(shape.ColorFlag);
                return shape;
            }
            return null;
        }

        public CandleShape AddCandle(string candleName, string openfield, string highfield, string lowfield,
                                     string closefield, int panelID, bool displayTitleField)
        {
            if (((openfield != null) && (highfield != null)) && ((lowfield != null) && (closefield != null)))
            {
                if ((dataSource.Columns.Contains(openfield) || dataSource.Columns.Contains(highfield)) ||
                    (dataSource.Columns.Contains(lowfield) || dataSource.Columns.Contains(closefield)))
                {
                    return null;
                }
                if (dicChartDiv.ContainsKey(panelID))
                {
                    var div = dicChartDiv[panelID];
                    var shape = new CandleShape
                                    {
                                        Name = candleName,
                                        OpenField = openfield,
                                        HighField = highfield,
                                        LowField = lowfield,
                                        CloseField = closefield
                                    };
                    div.YScaleField.AddRange(new[] {openfield, highfield, lowfield, closefield});
                    shape.DownColor = Color.SkyBlue;
                    shape.UpColor = Color.Red;
                    shape.ShapeType = ShapeType.Candle;
                    shape.DisplayTitleField = displayTitleField;
                    var column = new DataColumn(openfield);
                    var column2 = new DataColumn(highfield);
                    var column3 = new DataColumn(lowfield);
                    var column4 = new DataColumn(closefield);
                    dataSource.Columns.Add(column);
                    dataSource.Columns.Add(column2);
                    dataSource.Columns.Add(column3);
                    dataSource.Columns.Add(column4);
                    dataSource.Columns.Add(shape.ColorFlag);
                    div.ShapeDic.Add(candleName, shape);
                    return shape;
                }
            }
            return null;
        }

        public int AddchartDiv(int verticalPercent)
        {
            var y = 0;
            foreach (var div in dicChartDiv.Values)
            {
                y += Convert.ToInt32((((div.VerticalPercent)/100.0)*base.Height));
            }
            var height = Convert.ToInt32((((verticalPercent)/100.0)*base.Height));
            var div2 = new ChartDiv
                           {
                               VerticalPercent = verticalPercent,
                               PanelID = CreatePanelID(),
                               Rect = new Rectangle(0, y, base.Width, height)
                           };
            dicChartDiv[div2.PanelID] = div2;
            return div2.PanelID;
        }

        public int AddChartDiv()
        {
            double num = dicChartDiv.Count + 1;
            var num2 = (num - 1.0)/num;
            var num3 = 0;
            foreach (var div in dicChartDiv.Values)
            {
                div.VerticalPercent = Convert.ToInt32((div.VerticalPercent*num2));
                num3 += div.VerticalPercent;
            }
            var num4 = AddchartDiv(100 - num3);
            ResetSize();
            return num4;
        }

        public BaseIndicator AddIndicator(IndicatorType indType)
        {
            var item = GetIndicator(indType);
            if (item != null)
            {
                item.Crab = this;
                _indList.Add(item);
            }
            return item;
        }

        public LineShape AddLine(string name, int panelID)
        {
            if (((name != null) && !dataSource.Columns.Contains(name)) && dicChartDiv.ContainsKey(panelID))
            {
                var div = dicChartDiv[panelID];
                var shape = new LineShape
                                {
                                    LineColor = Color.Yellow,
                                    Name = name,
                                    ShapeType = ShapeType.Line
                                };
                div.YScaleField.Add(name);
                shape.DisplayName = name;
                div.ShapeDic.Add(name, shape);
                var column = new DataColumn(name);
                dataSource.Columns.Add(column);
                return shape;
            }
            return null;
        }

        public MarkShape AddMark(int panelID, string name, string displayName, double tick, int digit)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                var div = dicChartDiv[panelID];
                var shape = new MarkShape
                                {
                                    Name = name,
                                    DisplayName = displayName,
                                    ShapeType = ShapeType.Signal,
                                    Tick = tick,
                                    Digit = digit
                                };
                dataSource.Columns.Add(shape.MarkStyleField);
                dataSource.Columns.Add(shape.MarkDescField);
                dataSource.Columns.Add(shape.Name);
                div.ShapeDic.Add(name, shape);
                return shape;
            }
            return null;
        }

        public PaintLineBase AddPaintLine(Color lineColor, Color selectedColor, PaintLineType type, Point mp,
                                          int lineWidth, float[] dashPattern, int panelID)
        {
            if ((dataSource.Rows.Count >= 2) && dicChartDiv.ContainsKey(panelID))
            {
                var div = dicChartDiv[panelID];
                PaintLineBase item = null;
                var indexByPoint = GetIndexByPoint(mp);
                if ((indexByPoint < 0) || (indexByPoint > (lastVisibleRecord - 1)))
                {
                    return null;
                }
                GetValueByPoint(mp);
                item = CreatePaintLine(type);
                if (item != null)
                {
                    item.CgInstance = this;
                    item.OwnedPanelID = panelID;
                    item.LineColor = lineColor;
                    item.SelectedColor = selectedColor;
                    item.LineType = type;
                    item.Selected = true;
                    item.LineWidth = lineWidth;
                    item.LineStyle = dashPattern;
                    item.ZOrder = Common.GetNewNumber();
                    if (item.Init(mp))
                    {
                        div.PaintLineList.Add(item);
                        SelectedPaintLine = item;
                        isScrollByMouse = false;
                        selectState = 0;
                        item.BeginMove();
                    }
                }
            }
            return null;
        }

        public void AddYScaleFieldByShape(string bsName)
        {
            foreach (var div in dicChartDiv.Values)
            {
                if ((bsName == null) || !div.ShapeDic.ContainsKey(bsName))
                {
                    continue;
                }
                var shape = div.ShapeDic[bsName];
                if (shape.ShapeType == ShapeType.Candle)
                {
                    var shape2 = shape as CandleShape;
                    if (!div.YScaleField.Contains(shape2.OpenField))
                    {
                        div.YScaleField.Add(shape2.OpenField);
                    }
                    if (!div.YScaleField.Contains(shape2.HighField))
                    {
                        div.YScaleField.Add(shape2.HighField);
                    }
                    if (!div.YScaleField.Contains(shape2.LowField))
                    {
                        div.YScaleField.Add(shape2.LowField);
                    }
                    if (!div.YScaleField.Contains(shape2.CloseField))
                    {
                        div.YScaleField.Add(shape2.CloseField);
                    }
                }
                else if (!div.YScaleField.Contains(shape.Name))
                {
                    div.YScaleField.Add(shape.Name);
                }
                break;
            }
        }

        public void AutoResetVisibleRecord()
        {
            if (dataSource.Rows.Count == 0)
            {
                firstVisibleRecord = 0;
                lastVisibleRecord = 0;
                _spaceRecord = 0;
            }
            else
            {
                var maxVisibleRecord = GetMaxVisibleRecord();
                if (dataSource.Rows.Count < maxVisibleRecord)
                {
                    _spaceRecord = 0;
                    lastVisibleRecord = dataSource.Rows.Count;
                    firstVisibleRecord = 1;
                }
                else if (((firstVisibleRecord != 0) && (LastVisibleRecord != 0)) && !lastRecordIsVisible)
                {
                    _spaceRecord = 0;
                    var row = dataSource.Rows.Find(lastVisibleTimeKey);
                    if (row != null)
                    {
                        var index = dataSource.Rows.IndexOf(row);
                        lastVisibleRecord = index + 1;
                    }
                    firstVisibleRecord = (LastVisibleRecord - maxVisibleRecord) + 1;
                    if (firstVisibleRecord < 1)
                    {
                        firstVisibleRecord = 1;
                    }
                }
                else
                {
                    lastVisibleRecord = dataSource.Rows.Count;
                    if (_spaceRecord != 0)
                    {
                        var num3 = lastVisibleRecord - _spaceRecord;
                        if (num3 > (GetMaxVisibleRecord()*0.1))
                        {
                            firstVisibleRecord = (lastVisibleRecord - maxVisibleRecord) + 1;
                            _spaceRecord = 0;
                        }
                    }
                    else
                    {
                        firstVisibleRecord = (lastVisibleRecord - maxVisibleRecord) + 1;
                    }
                    if (firstVisibleRecord > lastVisibleRecord)
                    {
                        firstVisibleRecord = lastVisibleRecord;
                    }
                }
            }
        }

        private void ChartGraph_HandleCreated(object sender, EventArgs e)
        {
            new Thread(CheckMouseMoveLoop) {IsBackground = true}.Start();
            new Thread(CheckDrawGraphLoop) {IsBackground = true}.Start();
        }

        private void ChartGraph_KeyUp(object sender, KeyEventArgs e)
        {
            scrollStep = 1;
        }

        private void ChartGraph_MouseDown(object sender, MouseEventArgs e)
        {
            _isMultiSelect = false;
            var crossHairPoint = GetCrossHairPoint();
            crossStopIndex = GetMouseOverIndex();
            UserResizePanel = null;
            var count = GetAllSelectedShape().Count;
            if ((e.Clicks == 1) && (e.Button == MouseButtons.Left))
            {
                ClearSelectedPaintLine();
            }
            _offSetMenu.BeginMoveFlag = false;
            if ((count == 1) && _allowShowShapeMenu)
            {
                var shape = GetAllSelectedShape()[0];
                var rectangle = new Rectangle(_offSetMenu.Locaition,
                                              new Size(60,
                                                       _offSetMenu.GetDefaultButtonRect().Bottom - _offSetMenu.Locaition.Y));
                if (rectangle.Contains(e.Location))
                {
                    if (_offSetMenu.GetUpRect().Contains(e.Location))
                    {
                        if (shape.ZOrder == 0)
                        {
                            shape.OffSet += _offSetMenu.CurStep;
                            AddYScaleFieldByShape(shape.Name);
                            SetVisibleExtremeValue();
                            CreateAndDrawGraph();
                            return;
                        }
                        Cursor = Cursors.No;
                        return;
                    }
                    if (_offSetMenu.GetDownRect().Contains(e.Location))
                    {
                        if (shape.ZOrder == 0)
                        {
                            shape.OffSet -= _offSetMenu.CurStep;
                            AddYScaleFieldByShape(shape.Name);
                            SetVisibleExtremeValue();
                            CreateAndDrawGraph();
                            return;
                        }
                        Cursor = Cursors.No;
                        return;
                    }
                    if (_offSetMenu.GetLeftRect().Contains(e.Location))
                    {
                        if (shape.ZOrder == 0)
                        {
                            shape.Zoom -= _offSetMenu.CurStep;
                            AddYScaleFieldByShape(shape.Name);
                            SetVisibleExtremeValue();
                            CreateAndDrawGraph();
                            return;
                        }
                        Cursor = Cursors.No;
                        return;
                    }
                    if (_offSetMenu.GetRightRect().Contains(e.Location))
                    {
                        if (shape.ZOrder == 0)
                        {
                            shape.Zoom += _offSetMenu.CurStep;
                            AddYScaleFieldByShape(shape.Name);
                            SetVisibleExtremeValue();
                            CreateAndDrawGraph();
                            return;
                        }
                        Cursor = Cursors.No;
                        return;
                    }
                    if (_offSetMenu.GetDefaultButtonRect().Contains(e.Location))
                    {
                        shape.Zoom = 1.0;
                        shape.OffSet = 0.0;
                        shape.ZOrder = 0;
                        AddYScaleFieldByShape(shape.Name);
                        SetVisibleExtremeValue();
                        CreateAndDrawGraph();
                        return;
                    }
                    var rectangle2 = new Rectangle(_offSetMenu.GetRangeUpRect().Left, _offSetMenu.GetRangeUpRect().Bottom,
                                                   14, _offSetMenu.RangeHeight);
                    if (rectangle2.Contains(e.Location))
                    {
                        _offSetMenu.CurStep = _offSetMenu.GetCurStepByMousePoint(e.Location);
                    }
                    if (_offSetMenu.GetMoveRect().Contains(e.Location))
                    {
                        _offSetMenu.BeginMoveFlag = true;
                        Cursor = Cursors.Hand;
                    }
                    drawMenuFlag = true;
                    return;
                }
            }
            if (lockGraph)
            {
                Cursor = Cursors.No;
            }
            else
            {
                CrossHairY = crossHairPoint.Y;
                if (e.Button == MouseButtons.Left)
                {
                    if (e.Clicks != 1)
                    {
                        ShowCrossHair = !ShowCrossHair;
                        ClearSelectedShape();
                        if (count != 0)
                        {
                            CreateAndDrawGraph();
                        }
                        else
                        {
                            drawCrossHairFlag = true;
                        }
                    }
                    else if (ShowCrossHair)
                    {
                        drawCrossHairFlag = true;
                    }
                    else if (ModifierKeys == Keys.Control)
                    {
                        if ((e.Location.X >= _leftYScaleWidth) && (e.Location.X <= (base.Width - _rightYScaleSpace)))
                        {
                            if (((JudgeSelectShape(crossStopIndex, CrossHairY, 2, false) != null) && !ShowCrossHair) &&
                                allowMoveShape)
                            {
                                Cursor = Cursors.Hand;
                                _isMultiSelect = true;
                            }
                            CreateAndDrawGraph();
                        }
                    }
                    else
                    {
                        var num2 = 0;
                        foreach (var div in dicChartDiv.Values)
                        {
                            num2++;
                            if (num2 == dicChartDiv.Count)
                            {
                                break;
                            }
                            var rectangle3 = new Rectangle(0, div.Rect.Bottom - 2, div.Rect.Width, 4);
                            if (rectangle3.Contains(crossHairPoint))
                            {
                                Cursor = Cursors.SizeNS;
                                UserResizePanel = div;
                                goto Label_0639;
                            }
                        }
                        if ((e.Location.X >= _leftYScaleWidth) && (e.Location.X <= (base.Width - _rightYScaleSpace)))
                        {
                            var mouseOverPanel = GetMouseOverPanel();
                            if (mouseOverPanel != -1)
                            {
                                foreach (var base2 in dicChartDiv[mouseOverPanel].PaintLineList)
                                {
                                    if (base2.JudgeSelect())
                                    {
                                        SelectedPaintLine = base2;
                                        base2.ZOrder = Common.GetNewNumber();
                                    }
                                }
                            }
                            if (SelectedPaintLine != null)
                            {
                                SelectedPaintLine.Selected = true;
                                if (count != 0)
                                {
                                    ClearSelectedShape();
                                    CreateAndDrawGraph();
                                }
                                else
                                {
                                    drawPaintLineFlag = true;
                                }
                                SelectedPaintLine.BeginMove();
                            }
                            else if (((JudgeSelectShape(crossStopIndex, CrossHairY, 1, false) != null) && !ShowCrossHair) &&
                                     allowMoveShape)
                            {
                                Cursor = Cursors.Cross;
                                CreateAndDrawGraph();
                            }
                            else if (UserResizePanel == null)
                            {
                                if (count != 0)
                                {
                                    CreateAndDrawGraph();
                                }
                                else
                                {
                                    isScrollByMouse = true;
                                    BeginScrollPoint = crossHairPoint;
                                    Cursor = Cursors.NoMoveHoriz;
                                }
                            }
                        }
                    }
                }
            }
            Label_0639:
            base.Focus();
        }

        private void ChartGraph_MouseMove(object sender, MouseEventArgs e)
        {
            VpIndex = -1;
            if (ShowCrossHair)
            {
                selectState = 0;
            }
            if (!lockGraph)
            {
                if (_offSetMenu.BeginMoveFlag)
                {
                    _offSetMenu.Locaition = e.Location;
                    drawMenuFlag = true;
                    return;
                }
                if ((lastMouseMoveTime.AddTicks(0xf4240L) < DateTime.Now) && (GetAllSelectedShape().Count > 0))
                {
                    DrawGraph();
                }
                lastMouseMoveTime = DateTime.Now;
                CheckVpFlag = true;
                if ((SelectedPaintLine != null) && (e.Button == MouseButtons.Left))
                {
                    if ((e.Y >= dicChartDiv[SelectedPaintLine.OwnedPanelID].Rect.Y) &&
                        (e.Y <= dicChartDiv[SelectedPaintLine.OwnedPanelID].Rect.Bottom))
                    {
                        SelectedPaintLine.Move();
                        drawPaintLineFlag = true;
                    }
                }
                else if (isScrollByMouse)
                {
                    if ((e.Location.X >= _leftYScaleWidth) && (e.Location.X <= (base.Width - _rightYScaleSpace)))
                    {
                        if (e.Location.X < BeginScrollPoint.X)
                        {
                            Cursor = Cursors.PanWest;
                        }
                        else if (e.Location.X > BeginScrollPoint.X)
                        {
                            Cursor = Cursors.PanEast;
                        }
                        else
                        {
                            Cursor = Cursors.NoMoveHoriz;
                        }
                    }
                    else
                    {
                        Cursor = Cursors.No;
                    }
                    drawMouseScrollFlag = true;
                }
                else if (((UserResizePanel == null) && !ShowCrossHair) && (selectState == 0))
                {
                    var num = 0;
                    foreach (var div in dicChartDiv.Values)
                    {
                        num++;
                        if (num == dicChartDiv.Count)
                        {
                            break;
                        }
                        var rectangle = new Rectangle(0, div.Rect.Bottom - 2, div.Rect.Width, 4);
                        if (rectangle.Contains(GetCrossHairPoint()))
                        {
                            Cursor = Cursors.SizeNS;
                            goto Label_0298;
                        }
                    }
                    if (Cursor == Cursors.SizeNS)
                    {
                        Cursor = Cursors.Default;
                    }
                }
            }
            Label_0298:
            if (UserResizePanel != null)
            {
                drawDragFrameFlag = true;
            }
            if (ShowCrossHair)
            {
                crossStopIndex = GetMouseOverIndex();
                CrossHairY = GetCrossHairPoint().Y;
                _scrollCrossFlag = false;
                drawCrossHairFlag = true;
            }
        }

        private void ChartGraph_MouseUp(object sender, MouseEventArgs e)
        {
            Cursor = Cursors.Default;
            _offSetMenu.BeginMoveFlag = false;
            var crossHairPoint = GetCrossHairPoint();
            var flag = false;
            var allSelectedShape = GetAllSelectedShape();
            if ((allowMoveShape && (selectState > 0)) && (!ShowCrossHair && (allSelectedShape.Count > 0)))
            {
                if ((selectState == 2) && !_isMultiSelect)
                {
                    return;
                }
                var shape = allSelectedShape[0];
                var panelID = -1;
                foreach (var div in dicChartDiv.Values)
                {
                    if (div.ShapeDic.ContainsKey(shape.Name))
                    {
                        panelID = div.PanelID;
                    }
                    foreach (var shape2 in div.ShapeDic.Values)
                    {
                        if (shape2.Selected && !allSelectedShape.Contains(shape2))
                        {
                            allSelectedShape.Add(shape2);
                        }
                    }
                }
                foreach (var div2 in dicChartDiv.Values)
                {
                    if ((crossHairPoint.Y >= div2.Rect.Y) && (crossHairPoint.Y <= (div2.Rect.Y + div2.Rect.Height)))
                    {
                        if ((selectState == 2) && (div2.PanelID == panelID))
                        {
                            break;
                        }
                        var maximalZOrder = GetMaximalZOrder(div2.PanelID);
                        foreach (var shape3 in allSelectedShape)
                        {
                            if (shape3 is MarkShape)
                            {
                                var shape4 = shape3 as MarkShape;
                                if (div2.ShapeDic.ContainsKey(shape4.Name))
                                {
                                    continue;
                                }
                                UserDefinedTitle item = null;
                                foreach (var div3 in dicChartDiv.Values)
                                {
                                    if (div3.ShapeDic.ContainsKey(shape4.Name))
                                    {
                                        div3.ShapeDic.Remove(shape4.Name);
                                        if (div3.YScaleField.Contains(shape4.Name))
                                        {
                                            div3.YScaleField.Remove(shape4.Name);
                                        }
                                        foreach (var title2 in div3.TitleFieldList)
                                        {
                                            if (title2.TargetShapeField == shape4.Name)
                                            {
                                                item = title2;
                                            }
                                        }
                                        if (item != null)
                                        {
                                            div3.TitleFieldList.Remove(item);
                                        }
                                        break;
                                    }
                                }
                                shape4.OffSet = 0.0;
                                shape4.Zoom = 1.0;
                                div2.ShapeDic.Add(shape4.Name, shape4);
                                div2.YScaleField.Add(shape4.Name);
                                if (item != null)
                                {
                                    div2.TitleFieldList.Add(item);
                                }
                                if ((selectState == 2) || (selectState == 3))
                                {
                                    shape4.ZOrder = maximalZOrder + 1;
                                }
                                else
                                {
                                    shape4.ZOrder = 0;
                                }
                                flag = true;
                                continue;
                            }
                            if (shape3 is LineShape)
                            {
                                var shape5 = shape3 as LineShape;
                                if (div2.ShapeDic.ContainsKey(shape5.Name))
                                {
                                    continue;
                                }
                                UserDefinedTitle title3 = null;
                                foreach (var div4 in dicChartDiv.Values)
                                {
                                    if (div4.ShapeDic.ContainsKey(shape5.Name))
                                    {
                                        if (div4.YScaleField.Contains(shape5.Name))
                                        {
                                            div4.YScaleField.Remove(shape5.Name);
                                        }
                                        div4.ShapeDic.Remove(shape5.Name);
                                        foreach (var title4 in div4.TitleFieldList)
                                        {
                                            if (title4.TargetShapeField == shape5.Name)
                                            {
                                                title3 = title4;
                                            }
                                        }
                                        if (title3 != null)
                                        {
                                            div4.TitleFieldList.Remove(title3);
                                        }
                                        break;
                                    }
                                }
                                shape5.OffSet = 0.0;
                                shape5.Zoom = 1.0;
                                div2.ShapeDic.Add(shape5.Name, shape5);
                                div2.YScaleField.Add(shape5.Name);
                                if (title3 != null)
                                {
                                    div2.TitleFieldList.Add(title3);
                                }
                                if ((selectState == 2) || (selectState == 3))
                                {
                                    shape5.ZOrder = maximalZOrder + 1;
                                }
                                else
                                {
                                    shape5.ZOrder = 0;
                                }
                                flag = true;
                                continue;
                            }
                            if (shape3 is BarShape)
                            {
                                var shape6 = shape3 as BarShape;
                                if (div2.ShapeDic.ContainsKey(shape6.Name))
                                {
                                    continue;
                                }
                                UserDefinedTitle title5 = null;
                                foreach (var div5 in dicChartDiv.Values)
                                {
                                    if (div5.ShapeDic.ContainsKey(shape6.Name))
                                    {
                                        if (div5.YScaleField.Contains(shape6.Name))
                                        {
                                            div5.YScaleField.Remove(shape6.Name);
                                        }
                                        div5.ShapeDic.Remove(shape6.Name);
                                        foreach (var title6 in div5.TitleFieldList)
                                        {
                                            if (title6.TargetShapeField == shape6.Name)
                                            {
                                                title5 = title6;
                                            }
                                        }
                                        if (title5 != null)
                                        {
                                            div5.TitleFieldList.Remove(title5);
                                        }
                                        break;
                                    }
                                }
                                if (title5 != null)
                                {
                                    div2.TitleFieldList.Add(title5);
                                }
                                shape6.OffSet = 0.0;
                                shape6.Zoom = 1.0;
                                div2.ShapeDic.Add(shape6.Name, shape6);
                                div2.YScaleField.Add(shape6.Name);
                                if ((selectState == 2) || (selectState == 3))
                                {
                                    shape6.ZOrder = maximalZOrder + 1;
                                }
                                else
                                {
                                    shape6.ZOrder = 0;
                                }
                                flag = true;
                                continue;
                            }
                            if (shape3 is CandleShape)
                            {
                                var shape7 = shape3 as CandleShape;
                                if (!div2.ShapeDic.ContainsKey(shape7.Name))
                                {
                                    var list2 = new List<UserDefinedTitle>();
                                    var list3 = new List<PaintLineBase>();
                                    foreach (var div6 in dicChartDiv.Values)
                                    {
                                        if (div6.ShapeDic.ContainsKey(shape7.Name))
                                        {
                                            if (div6.YScaleField.Contains(shape7.CloseField))
                                            {
                                                div6.YScaleField.Remove(shape7.CloseField);
                                            }
                                            if (div6.YScaleField.Contains(shape7.HighField))
                                            {
                                                div6.YScaleField.Remove(shape7.HighField);
                                            }
                                            if (div6.YScaleField.Contains(shape7.LowField))
                                            {
                                                div6.YScaleField.Remove(shape7.LowField);
                                            }
                                            if (div6.YScaleField.Contains(shape7.OpenField))
                                            {
                                                div6.YScaleField.Remove(shape7.OpenField);
                                            }
                                            div6.ShapeDic.Remove(shape7.Name);
                                            foreach (var title7 in div6.TitleFieldList)
                                            {
                                                if (((title7.TargetShapeField == shape7.OpenField) ||
                                                     (title7.TargetShapeField == shape7.HighField)) ||
                                                    ((title7.TargetShapeField == shape7.LowField) ||
                                                     (title7.TargetShapeField == shape7.CloseField)))
                                                {
                                                    list2.Add(title7);
                                                }
                                            }
                                            foreach (var title8 in list2)
                                            {
                                                div6.TitleFieldList.Remove(title8);
                                            }
                                            foreach (var base2 in div6.PaintLineList)
                                            {
                                                if (((base2.BsName != null) && (base2.BsName.Length > 0)) &&
                                                    (base2.BsName == shape7.Name))
                                                {
                                                    list3.Add(base2);
                                                }
                                            }
                                            foreach (var base3 in list3)
                                            {
                                                div6.PaintLineList.Remove(base3);
                                            }
                                            continue;
                                        }
                                    }
                                    shape7.OffSet = 0.0;
                                    shape7.Zoom = 1.0;
                                    div2.ShapeDic.Add(shape7.Name, shape7);
                                    div2.YScaleField.Add(shape7.OpenField);
                                    div2.YScaleField.Add(shape7.HighField);
                                    div2.YScaleField.Add(shape7.CloseField);
                                    div2.YScaleField.Add(shape7.LowField);
                                    foreach (var base4 in list3)
                                    {
                                        div2.PaintLineList.Add(base4);
                                        base4.OwnedPanelID = div2.PanelID;
                                        base4.ZOrder = Common.GetNewNumber();
                                    }
                                    foreach (var title9 in list2)
                                    {
                                        div2.TitleFieldList.Add(title9);
                                    }
                                    if ((selectState == 2) || (selectState == 3))
                                    {
                                        shape7.ZOrder = maximalZOrder + 1;
                                    }
                                    else
                                    {
                                        shape7.ZOrder = 0;
                                    }
                                    flag = true;
                                }
                            }
                        }
                        continue;
                    }
                }
            }
            selectState = 0;
            if (flag)
            {
                RefreshGraph();
            }
            if (isScrollByMouse)
            {
                isScrollByMouse = !isScrollByMouse;
                if ((e.Location.X >= _leftYScaleWidth) && (e.Location.X <= (base.Width - _rightYScaleSpace)))
                {
                    if (crossHairPoint.X < BeginScrollPoint.X)
                    {
                        ScrollShape(ScrollType.ScrollRight,
                                    ((((BeginScrollPoint.X - crossHairPoint.X))/xScaleSpace) == 0f)
                                        ? ((int) 1f)
                                        : ((int) (((BeginScrollPoint.X - crossHairPoint.X))/xScaleSpace)));
                    }
                    else if (crossHairPoint.X > BeginScrollPoint.X)
                    {
                        ScrollShape(ScrollType.ScrollLeft,
                                    ((((crossHairPoint.X - BeginScrollPoint.X))/xScaleSpace) == 0f)
                                        ? ((int) 1f)
                                        : ((int) (((crossHairPoint.X - BeginScrollPoint.X))/xScaleSpace)));
                    }
                }
                scrollStep = 1;
                DrawMouseScroll();
            }
            ResizechartDiv();
            if (SelectedPaintLine != null)
            {
                SelectedPaintLine = null;
                drawPaintLineFlag = true;
            }
        }

        private void ChartGraph_MouseWheel(object sender, MouseEventArgs e)
        {
            if (!lockGraph)
            {
                if (e.Delta > 0)
                {
                    ZoomIn();
                }
                else
                {
                    ZoomOut();
                }
                SetVisibleExtremeValue();
                ResetCrossOverRecord();
                CreateAndDrawGraph();
                base.Focus();
            }
        }

        private void ChartGraph_SizeChanged(object sender, EventArgs e)
        {
            if ((base.Size.Width != 0) && (base.Size.Height != 0))
            {
                _spaceRecord = 0;
                ResetSize();
                RefreshGraph();
            }
        }

        public void CheckDrawGraphLoop()
        {
            while (_loopFlag)
            {
                if (drawDragFrameFlag)
                {
                    drawDragFrameFlag = !drawDragFrameFlag;
                    base.BeginInvoke(new DrawGraphDelegate(DrawDragFrame));
                }
                if (drawPaintLineFlag)
                {
                    drawPaintLineFlag = !drawPaintLineFlag;
                    base.BeginInvoke(new DrawGraphDelegate(DrawPaintLine));
                }
                if (drawCrossHairFlag)
                {
                    drawCrossHairFlag = !drawCrossHairFlag;
                    base.BeginInvoke(new DrawGraphDelegate(DrawCrossHair));
                }
                if (drawMouseScrollFlag)
                {
                    drawMouseScrollFlag = !drawMouseScrollFlag;
                    base.BeginInvoke(new DrawGraphDelegate(DrawMouseScroll));
                }
                if (drawValuePanelFlag)
                {
                    drawValuePanelFlag = !drawValuePanelFlag;
                    base.BeginInvoke(new DrawGraphDelegate(DrawValuePanel));
                }
                if (drawMenuFlag)
                {
                    drawMenuFlag = !drawMenuFlag;
                    base.BeginInvoke(new DrawGraphDelegate(DrawMenu));
                }
                Thread.Sleep(50);
            }
        }

        public void CheckMouseMoveLoop()
        {
            var num = 0x4c4b40;
            while (_loopFlag)
            {
                if ((lastMouseMoveTime.AddTicks(num) <= DateTime.Now) && CheckVpFlag)
                {
                    CheckVpFlag = !CheckVpFlag;
                    base.BeginInvoke(new DrawGraphDelegate(ShowValuePanel));
                }
                Thread.Sleep(100);
            }
        }

        public void ClearGraph()
        {
            dataSource.Clear();
            foreach (var div in dicChartDiv.Values)
            {
                div.EventTipObj.TipDic.Clear();
            }
            firstVisibleRecord = 0;
            LastVisibleRecord = 0;
            _spaceRecord = 0;
            ShowCrossHair = false;
            RefreshGraph();
        }

        public void ClearSelectedPaintLine()
        {
            foreach (var div in dicChartDiv.Values)
            {
                foreach (var base2 in div.PaintLineList)
                {
                    base2.Selected = false;
                }
            }
            SelectedPaintLine = null;
        }

        public void ClearSelectedShape()
        {
            foreach (var div in dicChartDiv.Values)
            {
                foreach (var shape in div.ShapeDic.Values)
                {
                    shape.Selected = false;
                }
            }
            selectState = 0;
        }

        public void CorrectVisibleRecordMistake()
        {
            if (dataSource.Rows.Count > 0)
            {
                if (firstVisibleRecord == 0)
                {
                    firstVisibleRecord = 1;
                }
                if (lastVisibleRecord == 0)
                {
                    lastVisibleRecord = 1;
                }
                if (firstVisibleRecord > lastVisibleRecord)
                {
                    firstVisibleRecord = lastVisibleRecord;
                }
                if (lastVisibleRecord < firstVisibleRecord)
                {
                    lastVisibleRecord = firstVisibleRecord;
                }
            }
        }

        public void CreateAndDrawGraph()
        {
            CreateBitmap();
            PaintGraph(DisplayRectangle);
        }

        public void CreateBitmap()
        {
            lock (UpdateLock)
            {
                if (_imgGraph != null)
                {
                    _imgGraph.Dispose();
                }
                _imgGraph = new Bitmap(base.Width, base.Height);
                var g = Graphics.FromImage(_imgGraph);
                foreach (var div in dicChartDiv.Values)
                {
                    paintBackGround(g, div);
                    paintScale(g, div);
                    if (!lockGraph)
                    {
                        paintShape(g, div);
                    }
                }
            }
        }

        public PaintLineBase CreatePaintLine(PaintLineType type)
        {
            switch (type)
            {
                case PaintLineType.LinearRegressionBand:
                    return new PaintLineLinearRegressionBand();

                case PaintLineType.LinearRegressionChannel:
                    return new PaintLineLinearRegressionChannel();

                case PaintLineType.LinearRegressionLine:
                    return new PaintLineLinearRegressionLine();

                case PaintLineType.DownArrow:
                    return new PaintLineDownArrow();

                case PaintLineType.Ellipse:
                    return new PaintLineEllipse();

                case PaintLineType.FibonacciEllipse:
                    return new PaintLineFibonacciEllipse();

                case PaintLineType.FibonacciFanLines:
                    return new PaintLineFibonacciFanLines();

                case PaintLineType.FibonacciTimeZones:
                    return new PaintLineFibonacciTimeZones();

                case PaintLineType.GannBox:
                    return new PaintLineGannBox();

                case PaintLineType.GannGrid:
                    return new PaintLineGannGrid();

                case PaintLineType.GannLine:
                    return new PaintLineGannLine();

                case PaintLineType.GoldenRatioLine:
                    return new PaintLineGoldenRatioLine();

                case PaintLineType.Horizontal:
                    return new PaintLineHorizontal();

                case PaintLineType.Percent:
                    return new PaintLinePercent();

                case PaintLineType.PeriodicLine:
                    return new PaintLinePeriodicLine();

                case PaintLineType.PriceTag:
                    return new PaintLinePriceTag();

                case PaintLineType.Rectangle:
                    return new PaintLineRectangle();

                case PaintLineType.Segment:
                    return new PaintLineSegment();

                case PaintLineType.SineLine:
                    return new PaintLineSineLine();

                case PaintLineType.SpeedResistanceLines:
                    return new PaintLineSpeedResistanceLines();

                case PaintLineType.TimeRuler:
                    return new PaintLineTimeRuler();

                case PaintLineType.Trend:
                    return new PaintLineTrend();

                case PaintLineType.Triangle:
                    return new PaintLineTriangle();

                case PaintLineType.UpArrow:
                    return new PaintLineUpArrow();

                case PaintLineType.Vertical:
                    return new PaintLineVertical();

                case PaintLineType.WaveRuler:
                    return new PaintLineWaveRuler();
            }
            return null;
        }

        public int CreatePanelID()
        {
            var valueList = new List<double>();
            foreach (var num in dicChartDiv.Keys)
            {
                valueList.Add(num);
            }
            return (((int) Common.GetHighValue(valueList)) + 1);
        }

        public bool DeleteIndicator(BaseIndicator indicator)
        {
            indicator.Remove();
            _indList.Remove(indicator);
            return true;
        }

        public bool DeleteShape(BaseShape obj)
        {
            foreach (var div in dicChartDiv.Values)
            {
                if (obj is LineShape)
                {
                    var shape = obj as LineShape;
                    if (div.ShapeDic.ContainsKey(shape.Name))
                    {
                        div.ShapeDic.Remove(shape.Name);
                        dataSource.Columns.Remove(shape.Name);
                        return true;
                    }
                }
                else
                {
                    if (obj is BarShape)
                    {
                        var shape2 = obj as BarShape;
                        if (div.ShapeDic.ContainsKey(shape2.Name))
                        {
                            div.ShapeDic.Remove(shape2.Name);
                            dataSource.Columns.Remove(shape2.Name);
                            return true;
                        }
                        continue;
                    }
                    if (obj is CandleShape)
                    {
                        var shape3 = obj as CandleShape;
                        if (div.ShapeDic.ContainsKey(shape3.Name))
                        {
                            div.ShapeDic.Remove(shape3.Name);
                            dataSource.Columns.Remove(shape3.CloseField);
                            dataSource.Columns.Remove(shape3.HighField);
                            dataSource.Columns.Remove(shape3.LowField);
                            dataSource.Columns.Remove(shape3.OpenField);
                            dataSource.Columns.Remove(shape3.ColorFlag);
                            return true;
                        }
                        continue;
                    }
                    if (obj is MarkShape)
                    {
                        var shape4 = obj as MarkShape;
                        if (div.ShapeDic.ContainsKey(shape4.Name))
                        {
                            div.ShapeDic.Remove(shape4.Name);
                            dataSource.Columns.Remove(shape4.MarkStyleField);
                            dataSource.Columns.Remove(shape4.Name);
                            dataSource.Columns.Remove(shape4.MarkDescField);
                        }
                    }
                }
            }
            return false;
        }

        protected override void Dispose(bool disposing)
        {
            _loopFlag = false;
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        public void DrawCrossHair()
        {
            lock (UpdateLock)
            {
                var graphics = BufferedGraphicsManager.Current.Allocate(base.CreateGraphics(),
                                                                        DisplayRectangle);
                var g = graphics.Graphics;
                g.DrawImage(_imgGraph, new Point(0, 0));
                foreach (var div in dicChartDiv.Values)
                {
                    paintDragLine(g, div);
                    if (!lockGraph && ShowCrossHair)
                    {
                        paintCrossHair(g, div);
                    }
                }
                paintTitle(g);
                paintMenu(g);
                graphics.Render();
                graphics.Dispose();
            }
        }

        public void DrawDragFrame()
        {
            lock (UpdateLock)
            {
                var graphics = BufferedGraphicsManager.Current.Allocate(base.CreateGraphics(),
                                                                        DisplayRectangle);
                var g = graphics.Graphics;
                g.DrawImage(_imgGraph, new Point(0, 0));
                foreach (var div in dicChartDiv.Values)
                {
                    paintDragLine(g, div);
                    if (!lockGraph && ShowCrossHair)
                    {
                        paintCrossHair(g, div);
                    }
                }
                paintTitle(g);
                paintDragFrame(g);
                paintMenu(g);
                graphics.Render();
                graphics.Dispose();
            }
        }

        public void DrawGraph()
        {
            PaintGraph(DisplayRectangle);
        }

        public void DrawGraph(Rectangle drawRectangle)
        {
            PaintGraph(drawRectangle);
        }

        public void DrawMenu()
        {
            lock (UpdateLock)
            {
                var graphics = BufferedGraphicsManager.Current.Allocate(base.CreateGraphics(),
                                                                        DisplayRectangle);
                var g = graphics.Graphics;
                g.DrawImage(_imgGraph, new Point(0, 0));
                foreach (var div in dicChartDiv.Values)
                {
                    paintDragLine(g, div);
                    if (!lockGraph && ShowCrossHair)
                    {
                        paintCrossHair(g, div);
                    }
                }
                paintTitle(g);
                paintMenu(g);
                graphics.Render();
                graphics.Dispose();
            }
        }

        public void DrawMouseScroll()
        {
            lock (UpdateLock)
            {
                var graphics = BufferedGraphicsManager.Current.Allocate(base.CreateGraphics(),
                                                                        DisplayRectangle);
                var g = graphics.Graphics;
                g.DrawImage(_imgGraph, new Point(0, 0));
                foreach (var div in dicChartDiv.Values)
                {
                    paintDragLine(g, div);
                    if (!lockGraph && ShowCrossHair)
                    {
                        paintCrossHair(g, div);
                    }
                }
                paintTitle(g);
                paintMouseScroll(g);
                paintMenu(g);
                graphics.Render();
                graphics.Dispose();
            }
        }

        public void DrawPaintLine()
        {
            lock (UpdateLock)
            {
                var graphics = BufferedGraphicsManager.Current.Allocate(base.CreateGraphics(),
                                                                        DisplayRectangle);
                var g = graphics.Graphics;
                g.DrawImage(_imgGraph, new Point(0, 0));
                foreach (var div in dicChartDiv.Values)
                {
                    paintDragLine(g, div);
                    if (!lockGraph && ShowCrossHair)
                    {
                        paintCrossHair(g, div);
                    }
                }
                paintTitle(g);
                paintMenu(g);
                graphics.Render();
                graphics.Dispose();
            }
        }

        public void DrawProcessBar()
        {
            lock (UpdateLock)
            {
                var graphics = BufferedGraphicsManager.Current.Allocate(base.CreateGraphics(),
                                                                        DisplayRectangle);
                var g = graphics.Graphics;
                g.DrawImage(_imgGraph, new Point(0, 0));
                foreach (var div in dicChartDiv.Values)
                {
                    paintDragLine(g, div);
                    if (!lockGraph && ShowCrossHair)
                    {
                        paintCrossHair(g, div);
                    }
                }
                paintTitle(g);
                paintProcessBar(g);
                paintMenu(g);
                graphics.Render();
                graphics.Dispose();
            }
        }

        public void DrawValuePanel()
        {
            lock (UpdateLock)
            {
                var graphics = BufferedGraphicsManager.Current.Allocate(base.CreateGraphics(),
                                                                        DisplayRectangle);
                var g = graphics.Graphics;
                g.DrawImage(_imgGraph, new Point(0, 0));
                foreach (var div in dicChartDiv.Values)
                {
                    paintDragLine(g, div);
                    if (!lockGraph && ShowCrossHair)
                    {
                        paintCrossHair(g, div);
                    }
                }
                paintTitle(g);
                if (!lockGraph)
                {
                    paintValuePanel(g);
                }
                paintProcessBar(g);
                paintMenu(g);
                graphics.Render();
                graphics.Dispose();
            }
        }

        public Dictionary<int, ChartDiv> GetAllchartDiv()
        {
            return dicChartDiv;
        }

        public List<BaseShape> GetAllSelectedShape()
        {
            var list = new List<BaseShape>();
            foreach (var div in dicChartDiv.Values)
            {
                foreach (var shape in div.ShapeDic.Values)
                {
                    if (shape.Selected)
                    {
                        list.Add(shape);
                    }
                }
            }
            return list;
        }

        public Point GetCrossHairPoint()
        {
            var x = base.PointToClient(MousePosition).X;
            var y = base.PointToClient(MousePosition).Y;
            foreach (var div in dicChartDiv.Values)
            {
                if ((y >= div.Rect.Y) && (y <= (div.Rect.Y + div.Rect.Height)))
                {
                    if (y > (base.Height - div.CalenderScale.Height))
                    {
                        y = base.Height - div.CalenderScale.Height;
                    }
                    if (x < _leftYScaleWidth)
                    {
                        x = _leftYScaleWidth;
                    }
                    if (x > (base.Width - _rightYScaleSpace))
                    {
                        x = base.Width - _rightYScaleSpace;
                    }
                    break;
                }
            }
            return new Point(x, y);
        }

        public double GetCrossOverValue()
        {
            GetCrossHairPoint();
            foreach (var div in dicChartDiv.Values)
            {
                if (((CrossHairY >= div.Rect.Y) && (CrossHairY <= (div.Rect.Y + div.Rect.Height))) &&
                    (GetWorkSpaceY(div.PanelID) > 0))
                {
                    var num = (div.MaxValue[0] - div.MinValue[0])/(GetWorkSpaceY(div.PanelID));
                    return (div.MaxValue[0] - (((CrossHairY - div.TitleHeight) - div.Rect.Y)*num));
                }
            }
            return 0.0;
        }

        public int GetCurrentPanel()
        {
            foreach (var div in dicChartDiv.Values)
            {
                if ((CrossHairY >= div.Rect.Y) && (CrossHairY <= (div.Rect.Y + div.Rect.Height)))
                {
                    return div.PanelID;
                }
            }
            return -1;
        }

        public double GetExtremValueByRecord(int record, int panelID, int flag)
        {
            if (record < 1)
            {
                return 0.0;
            }
            if (!dicChartDiv.ContainsKey(panelID))
            {
                return 0.0;
            }
            var valueList = new List<double>();
            var div = dicChartDiv[panelID];
            foreach (var shape in div.ShapeDic.Values)
            {
                if (shape.ZOrder != 0)
                {
                    continue;
                }
                if (shape.ShapeType == ShapeType.Candle)
                {
                    var shape2 = shape as CandleShape;
                    if (!(dataSource.Rows[record - 1][shape2.OpenField] is DBNull))
                    {
                        var num = 0.0;
                        double.TryParse(dataSource.Rows[record - 1][shape2.OpenField].ToString(), out num);
                        valueList.Add(num);
                    }
                    if (!(dataSource.Rows[record - 1][shape2.HighField] is DBNull))
                    {
                        var num2 = 0.0;
                        double.TryParse(dataSource.Rows[record - 1][shape2.HighField].ToString(), out num2);
                        valueList.Add(num2);
                    }
                    if (!(dataSource.Rows[record - 1][shape2.LowField] is DBNull))
                    {
                        var num3 = 0.0;
                        double.TryParse(dataSource.Rows[record - 1][shape2.LowField].ToString(), out num3);
                        valueList.Add(num3);
                    }
                    if (!(dataSource.Rows[record - 1][shape2.CloseField] is DBNull))
                    {
                        var num4 = 0.0;
                        double.TryParse(dataSource.Rows[record - 1][shape2.CloseField].ToString(), out num4);
                        valueList.Add(num4);
                    }
                    continue;
                }
                var result = 0.0;
                if (!(dataSource.Rows[record - 1][shape.Name] is DBNull))
                {
                    double.TryParse(dataSource.Rows[record - 1][shape.Name].ToString(), out result);
                    valueList.Add(result);
                }
            }
            if (flag == 0)
            {
                return Common.GetHighValue(valueList);
            }
            return Common.GetLowValue(valueList);
        }

        public Image GetImage()
        {
            Image image = new Bitmap(base.Width, base.Height);
            var g = Graphics.FromImage(image);
            g.DrawImage(_imgGraph, new Point(0, 0));
            foreach (var div in dicChartDiv.Values)
            {
                paintDragLine(g, div);
                if (!lockGraph && ShowCrossHair)
                {
                    paintCrossHair(g, div);
                }
            }
            paintTitle(g);
            paintDragFrame(g);
            paintProcessBar(g);
            paintMenu(g);
            g.Dispose();
            return image;
        }

        public int GetIndexByPoint(Point mp)
        {
            return (int) (((((mp.X - _leftYScaleWidth))/XScaleSpace) + firstVisibleRecord) - 1f);
        }

        public BaseIndicator GetIndicator(IndicatorType indType)
        {
            BaseIndicator indicator = null;
            switch (indType)
            {
                case IndicatorType.ADTM:
                    return new IndicatorADTM();

                case IndicatorType.ASI:
                    return new IndicatorAccumulationSwingIndex();

                case IndicatorType.ATR:
                    return new IndicatorAverageTrueRange();

                case IndicatorType.BBI:
                    return new IndicatorBullandBearIndex();

                case IndicatorType.BIAS:
                    return new IndicatorBIAS();

                case IndicatorType.BOLL:
                    return new IndicatorBollingerBands();

                case (IndicatorType.BIAS | IndicatorType.ATR):
                    return indicator;

                case IndicatorType.BS:
                    return new IndicatorExponentialMovingAverageCross();

                case IndicatorType.CCI:
                    return new IndicatorCommodityChannelIndex();

                case IndicatorType.CHAIKIN:
                    return new IndicatorChaikinOscillator();

                case IndicatorType.DDI:
                    return new IndicatorDirectionDeviationIndex();

                case IndicatorType.DMA:
                    return new IndicatorDifferentOfMovingAverage();

                case IndicatorType.DMI:
                    return new IndicatorDirectionalMovementIndex();

                case IndicatorType.DPO:
                    return new IndicatorDetrendedPriceOscillator();

                case IndicatorType.EMA:
                    return new IndicatorExponentialMovingAverage();

                case IndicatorType.KDJ:
                    return new IndicatorStochasticOscillator();

                case IndicatorType.LC:
                    return new IndicatorLargeCandle();

                case IndicatorType.LWR:
                    return new IndicatorLWR();

                case IndicatorType.NVI:
                    return new IndicatorNegativeVolumeIndex();

                case IndicatorType.MA:
                    return new IndicatorMovingAverage();

                case IndicatorType.MACD:
                    return new IndicatorMACD();

                case IndicatorType.MASS:
                    return new IndicatorMassIndex();

                case IndicatorType.MTM:
                    return new IndicatorMomentumIndex();

                case IndicatorType.OBV:
                    return new IndicatorOnBalanceVolume();

                case IndicatorType.OSC:
                    return new IndicatorOscillator();

                case IndicatorType.PBX:
                    return new IndicatorPBX();

                case IndicatorType.PSY:
                    return new IndicatorPsychologicalLine();

                case IndicatorType.PVI:
                    return new IndicatorPositiveVolumeIndex();

                case IndicatorType.ROC:
                    return new IndicatorRateOfChange();

                case IndicatorType.RSI:
                    return new IndicatorRelativeStrengthIndex();

                case IndicatorType.SD:
                    return new IndicatorStandardDeviation();

                case IndicatorType.SLOWKD:
                    return new IndicatorSlowStochasticOscillator();

                case IndicatorType.SMA:
                    return new IndicatorSimpleMovingAverage();

                case IndicatorType.TRIX:
                    return new IndicatorTripleExponentiallySmoothedMovingAverage();

                case IndicatorType.VR:
                    return new IndicatorVolumeRatio();

                case IndicatorType.WR:
                    return new IndicatorWilliamsAndRate();

                case IndicatorType.WVAD:
                    return new IndicatorWVAD();
            }
            return indicator;
        }

        public int GetMaximalZOrder(int panelID)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                var div = dicChartDiv[panelID];
                var valueList = new List<double>();
                foreach (var shape in div.ShapeDic.Values)
                {
                    valueList.Add(shape.ZOrder);
                }
                if (valueList.Count > 0)
                {
                    return (int) Common.GetHighValue(valueList);
                }
            }
            return -1;
        }

        public int GetMaxVisibleRecord()
        {
            if (xScaleSpace == 0f)
            {
                return (int) GetWorkSpaceX();
            }
            return (int) (GetWorkSpaceX()/XScaleSpace);
        }

        public int GetMouseOverIndex()
        {
            return (int) (((((GetCrossHairPoint().X - _leftYScaleWidth))/XScaleSpace) + firstVisibleRecord) - 1f);
        }

        public int GetMouseOverPanel()
        {
            foreach (var div in dicChartDiv.Values)
            {
                if ((GetCrossHairPoint().Y >= div.Rect.Y) && (GetCrossHairPoint().Y <= (div.Rect.Y + div.Rect.Height)))
                {
                    return div.PanelID;
                }
            }
            return -1;
        }

        public double GetMouseOverValue()
        {
            var crossHairPoint = GetCrossHairPoint();
            foreach (var div in dicChartDiv.Values)
            {
                if (((crossHairPoint.Y >= div.Rect.Y) && (crossHairPoint.Y <= (div.Rect.Y + div.Rect.Height))) &&
                    (GetWorkSpaceY(div.PanelID) > 0))
                {
                    var num = (div.MaxValue[0] - div.MinValue[0])/(GetWorkSpaceY(div.PanelID));
                    return (div.MaxValue[0] - (((crossHairPoint.Y - div.TitleHeight) - div.Rect.Y)*num));
                }
            }
            return 0.0;
        }

        public OffSetMenu GetOffSetMenu()
        {
            return _offSetMenu;
        }

        public ProcesBar GetProcessBar()
        {
            return processBarObject;
        }

        public int GetRecordByTime(DateTime dt)
        {
            Common.GetTimeKey(dt);
            return GetRecordByTime(dt);
        }

        public int GetRecordByTime(string timeKey)
        {
            var row = dataSource.Rows.Find(timeKey);
            if (row != null)
            {
                return (dataSource.Rows.IndexOf(row) + 1);
            }
            return 0;
        }

        public BaseShape GetShape(string bsName)
        {
            foreach (var div in dicChartDiv.Values)
            {
                if ((bsName != null) && div.ShapeDic.ContainsKey(bsName))
                {
                    return div.ShapeDic[bsName];
                }
            }
            return null;
        }

        public List<BaseShape> GetSortedShape(int panelID, string order)
        {
            var list = new List<BaseShape>();
            if (dicChartDiv.ContainsKey(panelID))
            {
                var div = dicChartDiv[panelID];
                foreach (var shape in div.ShapeDic.Values)
                {
                    if (shape.ShapeType == ShapeType.Signal)
                    {
                        if (order == "ASC")
                        {
                            list.Add(shape);
                        }
                        else
                        {
                            list.Insert(0, shape);
                        }
                    }
                }
                foreach (var shape2 in div.ShapeDic.Values)
                {
                    if (shape2.ShapeType == ShapeType.Line)
                    {
                        if (order == "ASC")
                        {
                            list.Add(shape2);
                        }
                        else
                        {
                            list.Insert(0, shape2);
                        }
                    }
                }
                foreach (var shape3 in div.ShapeDic.Values)
                {
                    if (shape3.ShapeType == ShapeType.Candle)
                    {
                        if (order == "ASC")
                        {
                            list.Add(shape3);
                        }
                        else
                        {
                            list.Insert(0, shape3);
                        }
                    }
                }
                foreach (var shape4 in div.ShapeDic.Values)
                {
                    if (shape4.ShapeType == ShapeType.Bar)
                    {
                        if (order == "ASC")
                        {
                            list.Add(shape4);
                        }
                        else
                        {
                            list.Insert(0, shape4);
                        }
                    }
                }
            }
            return list;
        }

        public object GetValue(string field, DateTime dateTime)
        {
            if (dataSource.Columns.Contains(field))
            {
                var timeKey = Common.GetTimeKey(dateTime);
                var row = dataSource.Rows.Find(timeKey);
                if ((row != null) && !(row[field] is DBNull))
                {
                    return row[field];
                }
            }
            return null;
        }

        public object GetValue(string field, int index)
        {
            if (dataSource.Rows.Count >= (index + 1))
            {
                if (!dataSource.Columns.Contains(field))
                {
                    return null;
                }
                var row = dataSource.Rows[index];
                if (!(row[field] is DBNull))
                {
                    return row[field];
                }
            }
            return null;
        }

        public double GetValueByPoint(Point mp)
        {
            foreach (var div in dicChartDiv.Values)
            {
                if (((mp.Y >= div.Rect.Y) && (mp.Y <= (div.Rect.Y + div.Rect.Height))) &&
                    (GetWorkSpaceY(div.PanelID) > 0))
                {
                    var num = (div.MaxValue[0] - div.MinValue[0])/(GetWorkSpaceY(div.PanelID));
                    return (div.MaxValue[0] - (((mp.Y - div.TitleHeight) - div.Rect.Y)*num));
                }
            }
            return 0.0;
        }

        public float GetWorkSpaceX()
        {
            return ((base.Width - _leftYScaleWidth) - _rightYScaleSpace);
        }

        public int GetWorkSpaceY(int panelID)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                return ((dicChartDiv[panelID].Rect.Height - dicChartDiv[panelID].CalenderScale.Height) -
                        ((int) dicChartDiv[panelID].TitleHeight));
            }
            return 0;
        }

        public float GetX(int pos)
        {
            return ((LeftYScaleWidth + (((pos + 1) - FirstVisibleRecord)*XScaleSpace)) + (XScaleSpace/2f));
        }

        public float GetY(int panelID, double chartValue, BaseShape bs)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                var div = dicChartDiv[panelID];
                var key = 0;
                if (bs != null)
                {
                    chartValue += bs.OffSet;
                    key = bs.ZOrder;
                }
                var num2 = 0.0;
                var num3 = 0.0;
                if (div.MaxValue.ContainsKey(key))
                {
                    num2 += div.MaxValue[key];
                }
                if (div.MinValue.ContainsKey(key))
                {
                    num3 += div.MinValue[key];
                }
                if (bs != null)
                {
                    chartValue *= bs.Zoom;
                }
                if ((num2 - num3) != 0.0)
                {
                    return
                        Convert.ToSingle((((((num2 - chartValue)/(num2 - num3))*GetWorkSpaceY(div.PanelID)) +
                                           div.TitleHeight) + div.Rect.Y));
                }
            }
            return 0f;
        }

        private void InitializeComponent()
        {
            components = new Container();
        }

        public BaseShape JudgeSelectShape(int curIndex, int mpY, int state, bool ignoreTitle)
        {
            BaseShape shape = null;
            var flag = false;
            var crossHairPoint = GetCrossHairPoint();
            if (!ignoreTitle)
            {
                foreach (var ef in ObjectRectDic.Keys)
                {
                    if (ef.Contains(crossHairPoint))
                    {
                        flag = true;
                        shape = ObjectRectDic[ef];
                        break;
                    }
                }
            }
            if (!lockGraph)
            {
                foreach (var div in dicChartDiv.Values)
                {
                    foreach (var shape2 in GetSortedShape(div.PanelID, "ASC"))
                    {
                        MarkShape shape3;
                        double num;
                        LineShape shape4;
                        double num5;
                        RectangleF ef3;
                        CandleShape shape5;
                        double num13;
                        BarShape shape6;
                        double num17;
                        if (flag)
                        {
                            if (shape2 == shape)
                            {
                                if (state != 0)
                                {
                                    shape2.Selected = true;
                                }
                            }
                            else if (state == 1)
                            {
                                shape2.Selected = false;
                            }
                        }
                        else if ((firstVisibleRecord == 0) || (LastVisibleRecord == 0))
                        {
                            if (state != 0)
                            {
                                shape2.Selected = false;
                            }
                        }
                        else
                        {
                            switch (shape2.ShapeType)
                            {
                                case ShapeType.Candle:
                                    {
                                        shape5 = shape2 as CandleShape;
                                        if (((curIndex >= 0) && (curIndex <= (LastVisibleRecord - 1))) &&
                                            (!(dataSource.Rows[curIndex][shape5.HighField].ToString() == "") &&
                                             !(dataSource.Rows[curIndex][shape5.LowField].ToString() == "")))
                                        {
                                            goto Label_0671;
                                        }
                                        if (state == 1)
                                        {
                                            shape5.Selected = false;
                                        }
                                        continue;
                                    }
                                case ShapeType.Bar:
                                    {
                                        shape6 = shape2 as BarShape;
                                        if (((curIndex >= 0) && (curIndex <= (LastVisibleRecord - 1))) &&
                                            !(dataSource.Rows[curIndex][shape6.Name].ToString() == ""))
                                        {
                                            goto Label_07B9;
                                        }
                                        if (state == 1)
                                        {
                                            shape6.Selected = false;
                                        }
                                        continue;
                                    }
                                case ShapeType.Line:
                                    {
                                        shape4 = shape2 as LineShape;
                                        if (((curIndex >= 0) && (curIndex <= (LastVisibleRecord - 1))) &&
                                            !(dataSource.Rows[curIndex][shape4.Name].ToString() == ""))
                                        {
                                            goto Label_0306;
                                        }
                                        if (state == 1)
                                        {
                                            shape4.Selected = false;
                                        }
                                        continue;
                                    }
                                case ShapeType.Signal:
                                    {
                                        shape3 = shape2 as MarkShape;
                                        if (((curIndex >= 0) && (curIndex <= (LastVisibleRecord - 1))) &&
                                            (!(dataSource.Rows[curIndex][shape3.Name] is DBNull) &&
                                             !(dataSource.Rows[curIndex][shape3.MarkStyleField] is DBNull)))
                                        {
                                            goto Label_01A5;
                                        }
                                        if (state == 1)
                                        {
                                            shape3.Selected = false;
                                        }
                                        continue;
                                    }
                            }
                        }
                        continue;
                        Label_01A5:
                        num = Convert.ToDouble(dataSource.Rows[curIndex][shape3.Name]);
                        var x = GetX(curIndex);
                        var markStyle =
                            (MarkStyle)
                            Enum.Parse(typeof (MarkStyle), dataSource.Rows[curIndex][shape3.MarkStyleField].ToString());
                        var ef2 = Common.GetSignaleMarkScope(x, GetY(div.PanelID, num, shape3), xScaleSpace,
                                                             markStyle);
                        var top = (int) ef2.Top;
                        var bottom = (int) ef2.Bottom;
                        if (((top >= div.Rect.Y) && (bottom <= (div.Rect.Y + div.Rect.Height))) &&
                            ((mpY >= top) && (mpY <= bottom)))
                        {
                            shape = shape3;
                            if (state != 0)
                            {
                                shape3.Selected = true;
                            }
                            flag = true;
                        }
                        else if (state == 1)
                        {
                            shape3.Selected = false;
                        }
                        continue;
                        Label_0306:
                        num5 = Convert.ToDouble(dataSource.Rows[curIndex][shape4.Name].ToString());
                        var num6 = GetX(curIndex);
                        var num8 = (int) GetY(div.PanelID, num5, shape4);
                        var point2 = GetCrossHairPoint();
                        var num9 = 0;
                        var num10 = num6;
                        if (point2.X >= num6)
                        {
                            if ((curIndex < (LastVisibleRecord - 1)) &&
                                (dataSource.Rows[curIndex + 1][shape4.Name].ToString() != ""))
                            {
                                var num11 = Convert.ToDouble(dataSource.Rows[curIndex + 1][shape4.Name].ToString());
                                num9 = Convert.ToInt32(GetY(div.PanelID, num11, shape4));
                                if ((num9 <= ((div.Rect.Y + div.Rect.Height) - div.CalenderScale.Height)) &&
                                    (num9 >= (div.Rect.Y + div.TitleHeight)))
                                {
                                    goto Label_0552;
                                }
                                if (state == 1)
                                {
                                    shape4.Selected = false;
                                }
                                continue;
                            }
                            num9 = num8;
                        }
                        else
                        {
                            num10 = num6 - xScaleSpace;
                            if ((curIndex > 0) && (dataSource.Rows[curIndex - 1][shape4.Name].ToString() != ""))
                            {
                                var num12 = Convert.ToDouble(dataSource.Rows[curIndex - 1][shape4.Name].ToString());
                                num9 = Convert.ToInt32(GetY(div.PanelID, num12, shape4));
                                if ((num9 <= ((div.Rect.Y + div.Rect.Height) - div.CalenderScale.Height)) &&
                                    (num9 >= (div.Rect.Y + div.TitleHeight)))
                                {
                                    goto Label_0552;
                                }
                                if (state == 1)
                                {
                                    shape4.Selected = false;
                                }
                                continue;
                            }
                            num9 = num8;
                        }
                        Label_0552:
                        ef3 = new RectangleF();
                        if (num9 >= num8)
                        {
                            ef3 = new RectangleF(num10, (num8 - 2), xScaleSpace,
                                                 ((num9 - num8) < 1) ? (1) : (((num9 - num8) + 4)));
                        }
                        else
                        {
                            ef3 = new RectangleF(num10, (num9 - 2), xScaleSpace,
                                                 ((num8 - num9) < 1) ? (1) : (((num8 - num9) + 4)));
                        }
                        if (ef3.Contains(point2))
                        {
                            shape = shape4;
                            if (state != 0)
                            {
                                shape4.Selected = true;
                            }
                            flag = true;
                        }
                        else if (state == 1)
                        {
                            shape4.Selected = false;
                        }
                        continue;
                        Label_0671:
                        num13 = Convert.ToDouble(dataSource.Rows[curIndex][shape5.HighField].ToString());
                        var chartValue = Convert.ToDouble(dataSource.Rows[curIndex][shape5.LowField].ToString());
                        var num15 = Convert.ToInt32(GetY(div.PanelID, num13, shape5));
                        var num16 = Convert.ToInt32(GetY(div.PanelID, chartValue, shape5));
                        if (((num15 >= div.Rect.Y) && (num16 <= (div.Rect.Y + div.Rect.Height))) &&
                            ((mpY >= num15) && (mpY <= num16)))
                        {
                            shape = shape5;
                            if (state != 0)
                            {
                                shape5.Selected = true;
                            }
                            flag = true;
                        }
                        else if (state == 1)
                        {
                            shape5.Selected = false;
                        }
                        continue;
                        Label_07B9:
                        num17 = Convert.ToDouble(dataSource.Rows[curIndex][shape6.Name].ToString());
                        var num18 = Convert.ToInt32(GetY(div.PanelID, num17, shape6));
                        var num19 = Convert.ToInt32(GetY(div.PanelID, 0.0, shape6));
                        if (num18 > num19)
                        {
                            num18 = Convert.ToInt32(GetY(div.PanelID, 0.0, shape6));
                            num19 = Convert.ToInt32(GetY(div.PanelID, num17, shape6));
                        }
                        if (((num18 >= div.Rect.Y) && (num19 <= (div.Rect.Y + div.Rect.Height))) &&
                            ((mpY >= num18) && (mpY <= num19)))
                        {
                            shape = shape6;
                            if (state != 0)
                            {
                                shape6.Selected = true;
                            }
                            flag = true;
                            continue;
                        }
                        if (state == 1)
                        {
                            shape6.Selected = false;
                        }
                    }
                }
            }
            selectState = state;
            return shape;
        }

        public void LocateCrossHair()
        {
            if (dataSource.Rows.Count > 0)
            {
                foreach (var div in dicChartDiv.Values)
                {
                    if ((((CrossHairY >= div.Rect.Y) && (CrossHairY <= (div.Rect.Y + div.Rect.Height))) &&
                         ((GetWorkSpaceY(div.PanelID) > 0) && (crossStopIndex >= 0))) &&
                        (crossStopIndex < dataSource.Rows.Count))
                    {
                        foreach (var shape in div.ShapeDic.Values)
                        {
                            if ((shape.ShapeType == ShapeType.Candle) &&
                                !(dataSource.Rows[crossStopIndex][(shape as CandleShape).CloseField] is DBNull))
                            {
                                var chartValue =
                                    Convert.ToDouble(dataSource.Rows[crossStopIndex][(shape as CandleShape).CloseField]);
                                CrossHairY = Convert.ToInt32(GetY(div.PanelID, chartValue, shape));
                                return;
                            }
                        }
                        foreach (var shape2 in div.ShapeDic.Values)
                        {
                            if ((shape2.ShapeType != ShapeType.Signal) &&
                                !(dataSource.Rows[crossStopIndex][shape2.Name] is DBNull))
                            {
                                var num2 = Convert.ToDouble(dataSource.Rows[crossStopIndex][shape2.Name]);
                                CrossHairY = Convert.ToInt32(GetY(div.PanelID, num2, shape2));
                                return;
                            }
                        }
                        continue;
                    }
                }
            }
        }

        private void paintBackGround(Graphics g, ChartDiv cp)
        {
            var x = 1f;
            float y = cp.Rect.Y;
            float width = cp.Rect.Width - 2;
            float height = cp.Rect.Height;
            if (width < 1f)
            {
                width = 1f;
            }
            if (height < 1f)
            {
                height = 1f;
            }
            g.FillRectangle(cp.BgBrush, x, y, width, height);
            g.DrawRectangle(cp.PanelBorder_Pen, x, y, width, height);
        }

        private void paintBar(Graphics g, ChartDiv cp, BarShape bs, int i, float scaleX, DataRow dr)
        {
            Color color2;
            if ((dr[bs.Name] is DBNull) || !(dr[bs.Name].ToString() != ""))
            {
                goto Label_051B;
            }
            var chartValue = Convert.ToDouble(dr[bs.Name]);
            var rect = new RectangleF();
            var tf = new PointF(((int) scaleX), GetY(cp.PanelID, 0.0, bs));
            var tf2 = new PointF(((int) scaleX), GetY(cp.PanelID, chartValue, bs));
            if (tf.Y >= tf2.Y)
            {
                rect = new RectangleF((((int) scaleX) - ((int) (xScaleSpace/4f))), GetY(cp.PanelID, chartValue, bs),
                                      ((((int) (xScaleSpace/5f))*2) + 1),
                                      GetY(cp.PanelID, 0.0, bs) - GetY(cp.PanelID, chartValue, bs));
            }
            else
            {
                rect = new RectangleF((((int) scaleX) - ((int) (xScaleSpace/4f))), GetY(cp.PanelID, 0.0, bs),
                                      ((((int) (xScaleSpace/5f))*2) + 1),
                                      GetY(cp.PanelID, chartValue, bs) - GetY(cp.PanelID, 0.0, bs));
            }
            var empty = Color.Empty;
            if (!(dr[bs.ColorFlag] is DBNull))
            {
                var strArray = dr[bs.ColorFlag].ToString().Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries);
                empty = Color.FromArgb(Convert.ToInt32(strArray[0]), Convert.ToInt32(strArray[1]),
                                       Convert.ToInt32(strArray[2]), Convert.ToInt32(strArray[3]));
            }
            Pen pen = null;
            if (empty != Color.Empty)
            {
                pen = new Pen(empty);
            }
            else if (tf.Y >= tf2.Y)
            {
                pen = bs.Up_Pen;
            }
            else
            {
                pen = bs.Down_Pen;
            }
            switch (bs.BarStyle)
            {
                case BarStyle.Line:
                    {
                        float lineWidth = bs.LineWidth;
                        if (lineWidth > xScaleSpace)
                        {
                            lineWidth = xScaleSpace;
                        }
                        pen.Width = lineWidth;
                        if (tf.Y <= cp.Rect.Y)
                        {
                            tf.Y = cp.Rect.Y;
                        }
                        if (tf.Y >= cp.Rect.Bottom)
                        {
                            tf.Y = cp.Rect.Bottom;
                        }
                        if (tf2.Y <= cp.Rect.Y)
                        {
                            tf2.Y = cp.Rect.Y;
                        }
                        if (tf2.Y >= cp.Rect.Bottom)
                        {
                            tf2.Y = cp.Rect.Bottom;
                        }
                        g.DrawLine(pen, tf, tf2);
                        pen.Width = 1f;
                        goto Label_043E;
                    }
                case BarStyle.Bar:
                    if (tf.Y < tf2.Y)
                    {
                        Brush brush = new SolidBrush(pen.Color);
                        g.FillRectangle(brush, rect);
                        brush.Dispose();
                    }
                    else
                    {
                        g.FillRectangle(cp.BgBrush, rect);
                        g.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
                    }
                    goto Label_043E;

                case BarStyle.ThreeD:
                    color2 = bs.Up_LineColor;
                    if (!(empty != Color.Empty))
                    {
                        if (tf.Y < tf2.Y)
                        {
                            color2 = bs.Down_lineColor;
                        }
                        break;
                    }
                    color2 = empty;
                    break;

                default:
                    goto Label_043E;
            }
            Brush brush2 =
                new LinearGradientBrush(
                    new RectangleF(rect.X, rect.Y, (rect.Width == 0f) ? 1f : rect.Width,
                                   (rect.Height == 0f) ? 1f : rect.Height), Color.White, color2, 360f);
            g.FillRectangle(brush2, rect);
            brush2.Dispose();
            Label_043E:
            if (empty != Color.Empty)
            {
                pen.Dispose();
            }
            if (bs.Selected)
            {
                if (ShowCrossHair)
                {
                    bs.Selected = false;
                }
                else
                {
                    var num3 = GetMaxVisibleRecord()/30;
                    if (num3 < 2)
                    {
                        num3 = 2;
                    }
                    if ((((i%num3) == 0) && (GetY(cp.PanelID, chartValue, bs) >= (cp.Rect.Y + cp.TitleHeight))) &&
                        (GetY(cp.PanelID, chartValue, bs) <= (cp.Rect.Bottom - cp.CalenderScale.Height)))
                    {
                        var ef2 = new RectangleF((((int) scaleX) - 3), GetY(cp.PanelID, chartValue, bs) - 3f, 6f, 6f);
                        g.FillRectangle(bs.Down_lineBrush, ef2);
                    }
                }
            }
            Label_051B:
            if (cp.MinValue[bs.ZOrder] < 0.0)
            {
                var num4 = ((LastVisibleRecord - firstVisibleRecord) + 1)*xScaleSpace;
                g.DrawLine(bs.Down_Pen, _leftYScaleWidth, GetY(cp.PanelID, 0.0, bs), _leftYScaleWidth + num4,
                           GetY(cp.PanelID, 0.0, bs));
            }
        }

        private void paintCandle(Graphics g, ChartDiv cp, CandleShape cs, int i, float scaleX, DataRow dr)
        {
            Brush brush4;
            Pen pen3;
            Pen pen4;
            var chartValue = 0.0;
            var num2 = 0.0;
            var num3 = 0.0;
            var num4 = 0.0;
            if (((dr[cs.OpenField] is DBNull) || (dr[cs.HighField] is DBNull)) ||
                ((dr[cs.LowField] is DBNull) || (dr[cs.CloseField] is DBNull)))
            {
                if (!cs.CrossFlag || (cs.CandleStyle != CandleStyle.Large))
                {
                    return;
                }
                var flag = true;
                for (var j = i; j >= 0; j--)
                {
                    var row = dataSource.Rows[j];
                    if ((!(row[cs.OpenField] is DBNull) && !(row[cs.HighField] is DBNull)) &&
                        (!(row[cs.LowField] is DBNull) && !(row[cs.CloseField] is DBNull)))
                    {
                        chartValue = Convert.ToDouble(row[cs.OpenField]);
                        num2 = Convert.ToDouble(row[cs.HighField]);
                        num3 = Convert.ToDouble(row[cs.LowField]);
                        num4 = Convert.ToDouble(row[cs.CloseField]);
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    return;
                }
            }
            else
            {
                chartValue = Convert.ToDouble(dr[cs.OpenField]);
                num2 = Convert.ToDouble(dr[cs.HighField]);
                num3 = Convert.ToDouble(dr[cs.LowField]);
                num4 = Convert.ToDouble(dr[cs.CloseField]);
            }
            if (GetWorkSpaceY(cp.PanelID) <= 0)
            {
                return;
            }
            var empty = Color.Empty;
            if (!(dr[cs.ColorFlag] is DBNull))
            {
                var strArray = dr[cs.ColorFlag].ToString().Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries);
                empty = Color.FromArgb(Convert.ToInt32(strArray[0]), Convert.ToInt32(strArray[1]),
                                       Convert.ToInt32(strArray[2]), Convert.ToInt32(strArray[3]));
            }
            if (chartValue > num4)
            {
                var height = 0f;
                height = ((chartValue - num4) != 0.0)
                             ? ((float)
                                (((chartValue - num4)/(cp.MaxValue[cs.ZOrder] - cp.MinValue[cs.ZOrder]))*
                                 GetWorkSpaceY(cp.PanelID)))
                             : 1f;
                if (height < 1f)
                {
                    height = 1f;
                }
                var rect = new RectangleF((((int) scaleX) - ((int) (xScaleSpace/4f))), GetY(cp.PanelID, chartValue, cs),
                                          ((((int) (xScaleSpace/4f))*2) + 1), height);
                brush4 = null;
                pen3 = null;
                pen4 = null;
                if (empty == Color.Empty)
                {
                    brush4 = cs.DownLineBrush;
                    pen3 = cs.DownLinePen;
                    pen4 = cs.MiddleDownLinePen;
                }
                else
                {
                    brush4 = new SolidBrush(empty);
                    pen3 = new Pen(empty);
                    pen4 = new Pen(empty);
                }
                switch (cs.CandleStyle)
                {
                    case CandleStyle.Standard:
                        g.DrawLine(pen4, scaleX, GetY(cp.PanelID, num2, cs), scaleX, GetY(cp.PanelID, num3, cs));
                        g.FillRectangle(brush4, rect);
                        goto Label_0966;

                    case CandleStyle.American:
                        g.DrawLine(pen3, scaleX, GetY(cp.PanelID, num2, cs), scaleX, GetY(cp.PanelID, num3, cs));
                        g.DrawLine(pen3, scaleX - (xScaleSpace/4f), GetY(cp.PanelID, chartValue, cs), scaleX,
                                   GetY(cp.PanelID, chartValue, cs));
                        g.DrawLine(pen3, scaleX, GetY(cp.PanelID, num4, cs), scaleX + (xScaleSpace/4f),
                                   GetY(cp.PanelID, num4, cs));
                        goto Label_0966;

                    case CandleStyle.ThreeD:
                        {
                            g.DrawLine(pen4, scaleX, GetY(cp.PanelID, num2, cs), scaleX, GetY(cp.PanelID, num3, cs));
                            var brush5 =
                                new LinearGradientBrush(
                                    new Rectangle((int) rect.X, (int) rect.Y, (int) rect.Width, (int) rect.Height),
                                    Color.White, pen3.Color, 1f);
                            g.FillRectangle(brush5,
                                            new Rectangle((int) rect.X, (int) rect.Y, (int) rect.Width,
                                                          (int) rect.Height));
                            brush5.Dispose();
                            goto Label_0966;
                        }
                    case CandleStyle.Large:
                        {
                            Brush brush6 = new SolidBrush(pen4.Color);
                            var num10 = GetY(cp.PanelID, num3, cs) - GetY(cp.PanelID, num2, cs);
                            if (num10 < 1f)
                            {
                                num10 = 1f;
                            }
                            var num11 = GetY(cp.PanelID, num4, cs) - GetY(cp.PanelID, chartValue, cs);
                            if (num11 < 1f)
                            {
                                num11 = 1f;
                            }
                            g.FillRectangle(brush6,
                                            new RectangleF(scaleX - (xScaleSpace/2f), GetY(cp.PanelID, num2, cs),
                                                           xScaleSpace, num10));
                            g.FillRectangle(brush4,
                                            new RectangleF(scaleX - (xScaleSpace/2f), GetY(cp.PanelID, chartValue, cs),
                                                           xScaleSpace, num11));
                            brush6.Dispose();
                            goto Label_0966;
                        }
                }
            }
            else
            {
                var num6 = 0f;
                num6 = ((num4 - chartValue) != 0.0)
                           ? ((float)
                              (((num4 - chartValue)/(cp.MaxValue[cs.ZOrder] - cp.MinValue[cs.ZOrder]))*
                               GetWorkSpaceY(cp.PanelID)))
                           : 1f;
                if (num6 < 1f)
                {
                    num6 = 1f;
                }
                var ef = new RectangleF((((int) scaleX) - ((int) (xScaleSpace/4f))), GetY(cp.PanelID, num4, cs),
                                        ((((int) (xScaleSpace/4f))*2) + 1), num6);
                Pen pen = null;
                Pen pen2 = null;
                if (empty == Color.Empty)
                {
                    pen = cs.UpLinePen;
                    pen2 = cs.MiddleUpLinePen;
                }
                else
                {
                    pen = new Pen(empty);
                    pen2 = new Pen(empty);
                }
                switch (cs.CandleStyle)
                {
                    case CandleStyle.Standard:
                        g.DrawLine(pen2, scaleX, GetY(cp.PanelID, num2, cs), scaleX, GetY(cp.PanelID, num3, cs));
                        g.FillRectangle(cp.BgBrush,
                                        new Rectangle(((int) ef.X) + 1, ((int) ef.Y) + 1, ((int) ef.Width) - 2,
                                                      ((int) ef.Height) - 1));
                        g.DrawRectangle(pen, new Rectangle((int) ef.X, (int) ef.Y, (int) ef.Width, (int) ef.Height));
                        break;

                    case CandleStyle.American:
                        g.DrawLine(pen, scaleX, GetY(cp.PanelID, num2, cs), scaleX, GetY(cp.PanelID, num3, cs));
                        g.DrawLine(pen, scaleX - (xScaleSpace/4f), GetY(cp.PanelID, chartValue, cs), scaleX,
                                   GetY(cp.PanelID, chartValue, cs));
                        g.DrawLine(pen, scaleX, GetY(cp.PanelID, num4, cs), scaleX + (xScaleSpace/4f),
                                   GetY(cp.PanelID, num4, cs));
                        break;

                    case CandleStyle.ThreeD:
                        {
                            g.DrawLine(pen2, scaleX, GetY(cp.PanelID, num2, cs), scaleX, GetY(cp.PanelID, num3, cs));
                            var brush =
                                new LinearGradientBrush(
                                    new Rectangle((int) ef.X, (int) ef.Y, (int) ef.Width, (int) ef.Height), Color.White,
                                    pen.Color, 360f);
                            g.FillRectangle(brush,
                                            new Rectangle((int) ef.X, (int) ef.Y, (int) ef.Width, (int) ef.Height));
                            brush.Dispose();
                            break;
                        }
                    case CandleStyle.Large:
                        {
                            Brush brush2 = new SolidBrush(pen2.Color);
                            Brush brush3 = new SolidBrush(pen.Color);
                            var num7 = GetY(cp.PanelID, num3, cs) - GetY(cp.PanelID, num2, cs);
                            if (num7 < 1f)
                            {
                                num7 = 1f;
                            }
                            var num8 = GetY(cp.PanelID, chartValue, cs) - GetY(cp.PanelID, num4, cs);
                            if (num8 < 1f)
                            {
                                num8 = 1f;
                            }
                            g.FillRectangle(brush2,
                                            new RectangleF(scaleX - (xScaleSpace/2f), GetY(cp.PanelID, num2, cs),
                                                           xScaleSpace, num7));
                            g.FillRectangle(brush3,
                                            new RectangleF(scaleX - (xScaleSpace/2f), GetY(cp.PanelID, num4, cs),
                                                           xScaleSpace, num8));
                            brush2.Dispose();
                            brush3.Dispose();
                            break;
                        }
                }
                if (empty != Color.Empty)
                {
                    pen.Dispose();
                    pen2.Dispose();
                }
                goto Label_0989;
            }
            Label_0966:
            if (empty != Color.Empty)
            {
                brush4.Dispose();
                pen3.Dispose();
                pen4.Dispose();
            }
            Label_0989:
            if (cs.Selected)
            {
                if (ShowCrossHair)
                {
                    cs.Selected = false;
                    return;
                }
                var num12 = GetMaxVisibleRecord()/30;
                if (num12 < 2)
                {
                    num12 = 3;
                }
                if ((((i%num12) == 0) && (GetY(cp.PanelID, num4, cs) >= (cp.Rect.Y + cp.TitleHeight))) &&
                    (GetY(cp.PanelID, num4, cs) <= (cp.Rect.Bottom - cp.CalenderScale.Height)))
                {
                    var ef3 = new RectangleF((((int) scaleX) - 3), GetY(cp.PanelID, num4, cs), 6f, 6f);
                    g.FillRectangle(Brushes.White, ef3);
                }
            }
        }

        private void paintCrossHair(Graphics g, ChartDiv cp)
        {
            if (ShowCrossHair)
            {
                var crossHairPoint = GetCrossHairPoint();
                if (CrossHairY != -1)
                {
                    crossHairPoint.Y = CrossHairY;
                    if ((crossHairPoint.Y >= (cp.Rect.Y + cp.TitleHeight)) &&
                        (crossHairPoint.Y <= ((cp.Rect.Y + cp.Rect.Height) - cp.CalenderScale.Height)))
                    {
                        g.DrawLine(cp.CrossHair_Pen, _leftYScaleWidth, crossHairPoint.Y, base.Width - _rightYScaleSpace,
                                   crossHairPoint.Y);
                    }
                    var x = GetX(CrossStopIndex);
                    if (!_scrollCrossFlag)
                    {
                        x = crossHairPoint.X;
                    }
                    var ef = g.MeasureString(" ", cp.TitleFont);
                    if (((crossStopIndex == -1) || (crossStopIndex < (firstVisibleRecord - 1))) ||
                        (crossStopIndex > (LastVisibleRecord - 1)))
                    {
                        g.DrawLine(cp.CrossHair_Pen, x, (cp.Rect.Y + 5) + ef.Height, x,
                                   ((cp.Rect.Y + cp.Rect.Height) - cp.CalenderScale.Height));
                    }
                    else
                    {
                        var num2 = (cp.Rect.Y + 5) + ef.Height;
                        g.DrawLine(cp.CrossHair_Pen, x, num2, x,
                                   ((cp.Rect.Y + cp.Rect.Height) - cp.CalenderScale.Height));
                        if (cp.CalenderScale.Visible)
                        {
                            var ef2 =
                                g.MeasureString(
                                    Common.GetCalenderFormatTimeKey(
                                        dataSource.Rows[crossStopIndex][calenderScaleField].ToString(),
                                        cp.CalenderScale.CalenderFormat), cp.CalenderScale.TipFont);
                            var rect = new RectangleF((x - (ef2.Width/2f)) - 2f,
                                                      (((cp.Rect.Y + cp.Rect.Height) - cp.CalenderScale.Height) + 1),
                                                      ef2.Width + 4f, ef2.Height + 2f);
                            var roundRectangle = Common.GetRoundRectangle(1, rect);
                            g.FillPath(cp.CalenderScale.Tip_Brush, roundRectangle);
                            g.DrawPath(cp.CalenderScale.TipFont_Pen, roundRectangle);
                            roundRectangle.Dispose();
                            g.DrawString(
                                Common.GetCalenderFormatTimeKey(
                                    dataSource.Rows[crossStopIndex][calenderScaleField].ToString(),
                                    cp.CalenderScale.CalenderFormat), cp.CalenderScale.TipFont,
                                cp.CalenderScale.TipFont_Brush, rect);
                        }
                        if ((crossHairPoint.Y >= (cp.Rect.Y + cp.TitleHeight)) &&
                            (crossHairPoint.Y <= ((cp.Rect.Y + cp.Rect.Height) - cp.CalenderScale.Height)))
                        {
                            var crossOverValue = GetCrossOverValue();
                            if (_leftYScaleWidth != 0)
                            {
                                var text = Common.GetValueByDigit(crossOverValue, cp.LeftYScale.Digit, true);
                                var ef4 = g.MeasureString(text, cp.LeftYScale.TipFont);
                                var ef5 = new RectangleF((_leftYScaleWidth - ef4.Width) - 4f,
                                                         crossHairPoint.Y - (ef4.Height/2f), ef4.Width + 4f,
                                                         ef4.Height + 1f);
                                var path = Common.GetRoundRectangle(1, ef5);
                                g.FillPath(cp.LeftYScale.Tip_Brush, path);
                                g.DrawPath(cp.LeftYScale.TipFont_Pen, path);
                                path.Dispose();
                                g.DrawString(text, cp.LeftYScale.TipFont, cp.LeftYScale.TipFont_Brush, ef5);
                            }
                            if (_rightYScaleSpace != 0)
                            {
                                var str2 = Common.GetValueByDigit(crossOverValue, cp.RightYScale.Digit, true);
                                var ef6 = g.MeasureString(str2, cp.RightYScale.TipFont);
                                var ef7 = new RectangleF(((base.Width - _rightYScaleSpace) + 1),
                                                         crossHairPoint.Y - (ef6.Height/2f), ef6.Width + 4f,
                                                         ef6.Height + 1f);
                                var path3 = Common.GetRoundRectangle(2, ef7);
                                g.FillPath(cp.RightYScale.Tip_Brush, path3);
                                g.DrawPath(cp.RightYScale.TipFont_Pen, path3);
                                path3.Dispose();
                                g.DrawString(str2, cp.RightYScale.TipFont, cp.RightYScale.TipFont_Brush, ef7);
                            }
                        }
                    }
                }
            }
        }

        private void paintDragFrame(Graphics g)
        {
            if (UserResizePanel != null)
            {
                var crossHairPoint = GetCrossHairPoint();
                ChartDiv div = null;
                var flag = false;
                foreach (var div2 in dicChartDiv.Values)
                {
                    if (flag)
                    {
                        div = div2;
                        break;
                    }
                    if (div2 == UserResizePanel)
                    {
                        flag = true;
                    }
                }
                var flag2 = false;
                if (UserResizePanel.Rect.Contains(crossHairPoint))
                {
                    flag2 = true;
                    Brush brush = new LinearGradientBrush(UserResizePanel.Rect,
                                                          Color.FromArgb(50,
                                                                         Common.GetReverseColor(
                                                                             UserResizePanel.BgBeginColor)),
                                                          Color.FromArgb(100,
                                                                         Common.GetReverseColor(
                                                                             UserResizePanel.BgEndColor)), 270f);
                    g.FillRectangle(brush, UserResizePanel.Rect);
                    brush.Dispose();
                }
                else if ((div != null) && div.Rect.Contains(crossHairPoint))
                {
                    Brush brush2 = new LinearGradientBrush(div.Rect,
                                                           Color.FromArgb(50,
                                                                          Common.GetReverseColor(
                                                                              UserResizePanel.BgBeginColor)),
                                                           Color.FromArgb(100, Common.GetReverseColor(div.BgEndColor)),
                                                           270f);
                    flag2 = true;
                    g.FillRectangle(brush2, div.Rect);
                    brush2.Dispose();
                }
                if (flag2)
                {
                    var pen = new Pen(Color.FromArgb(200, Color.White), 2f)
                                  {
                                      DashStyle = DashStyle.Dash
                                  };
                    g.DrawLine(pen, 0, crossHairPoint.Y, base.Width, crossHairPoint.Y);
                    pen.Dispose();
                }
            }
        }

        private void paintDragLine(Graphics g, ChartDiv cp)
        {
            var workSpaceX = (int) GetWorkSpaceX();
            var workSpaceY = GetWorkSpaceY(cp.PanelID);
            if ((workSpaceX > 0) && (workSpaceY > 0))
            {
                Image image = new Bitmap(workSpaceX, workSpaceY);
                var graphics = Graphics.FromImage(image);
                cp.PaintLineList.Sort(new PaintLineBase.PaintLineZOrderCompare());
                foreach (var base2 in cp.PaintLineList)
                {
                    graphics.SmoothingMode = SmoothingMode.Default;
                    base2.DrawToImage(graphics);
                }
                g.DrawImage(image, new PointF(_leftYScaleWidth, cp.Rect.Y + cp.TitleHeight));
                graphics.Dispose();
                image.Dispose();
            }
        }

        public void PaintGraph(Rectangle drawRectangle)
        {
            lock (UpdateLock)
            {
                var graphics = BufferedGraphicsManager.Current.Allocate(base.CreateGraphics(),
                                                                        drawRectangle);
                var g = graphics.Graphics;
                g.DrawImage(_imgGraph, new Point(0, 0));
                foreach (var div in dicChartDiv.Values)
                {
                    paintDragLine(g, div);
                    if (!lockGraph && ShowCrossHair)
                    {
                        paintCrossHair(g, div);
                    }
                }
                paintTitle(g);
                paintDragFrame(g);
                paintProcessBar(g);
                paintMenu(g);
                graphics.Render();
                graphics.Dispose();
            }
        }

        private void paintLine(Graphics g, GraphicsPath gp, ChartDiv cp, LineShape ls, int i, float scaleX,
                               int panelBottom, DataRow dr)
        {
            var tf = new PointF();
            var tf2 = new PointF();
            if (!(dr[ls.Name] is DBNull) && (dr[ls.Name].ToString() != ""))
            {
                var chartValue = Convert.ToDouble(dr[ls.Name]);
                if (dataSource.Rows.Count == 1)
                {
                    tf = new PointF((((int) scaleX) - ((int) (xScaleSpace/4f))), GetY(cp.PanelID, chartValue, ls));
                    tf2 = new PointF(
                        (((((int) scaleX) - ((int) (xScaleSpace/4f))) + (((int) (xScaleSpace/4f))*2)) + 1),
                        GetY(cp.PanelID, chartValue, ls));
                }
                else
                {
                    DataRow row = null;
                    var num2 = 0.0;
                    for (var j = i - 1; j >= (firstVisibleRecord - 1); j--)
                    {
                        dataSource.Rows[j][calenderScaleField].ToString();
                        var row2 = dataSource.Rows[j];
                        if (!(row2[ls.Name] is DBNull) && (row2[ls.Name].ToString() != ""))
                        {
                            var x = GetX(j);
                            num2 = Convert.ToDouble(row2[ls.Name]);
                            tf = new PointF(((int) x), GetY(cp.PanelID, num2, ls));
                            if (j != (i - 1))
                            {
                                var num5 = GetX(i);
                                tf2 = new PointF(((int) num5), GetY(cp.PanelID, num2, ls));
                                if (((tf.Y <= ((panelBottom - cp.CalenderScale.Height) + 1)) &&
                                     (tf.Y >= ((cp.Rect.Y + cp.TitleHeight) - 1f))) &&
                                    ((tf2.Y < ((panelBottom - cp.CalenderScale.Height) + 1)) &&
                                     (tf2.Y >= ((cp.Rect.Y + cp.TitleHeight) - 1f))))
                                {
                                    gp.AddLine(tf, tf2);
                                }
                                tf = new PointF(((int) num5), GetY(cp.PanelID, num2, ls));
                            }
                            row = row2;
                            break;
                        }
                    }
                    tf2 = new PointF(((int) scaleX), GetY(cp.PanelID, chartValue, ls));
                    if ((((row != null) && (tf.Y <= ((panelBottom - cp.CalenderScale.Height) + 1))) &&
                         ((tf.Y >= ((cp.Rect.Y + cp.TitleHeight) - 1f)) &&
                          (tf2.Y < ((panelBottom - cp.CalenderScale.Height) + 1)))) &&
                        (tf2.Y >= ((cp.Rect.Y + cp.TitleHeight) - 1f)))
                    {
                        gp.AddLine(tf, tf2);
                    }
                }
                if (ls.Selected)
                {
                    if (ShowCrossHair)
                    {
                        ls.Selected = false;
                    }
                    else
                    {
                        var num6 = GetMaxVisibleRecord()/30;
                        if (num6 < 1)
                        {
                            num6 = 1;
                        }
                        if ((((i%num6) == 0) && (GetY(cp.PanelID, chartValue, ls) >= (cp.Rect.Y + cp.TitleHeight))) &&
                            (GetY(cp.PanelID, chartValue, ls) <= (cp.Rect.Bottom - cp.CalenderScale.Height)))
                        {
                            var rect = new RectangleF((((int) scaleX) - 3), GetY(cp.PanelID, chartValue, ls) - 3f, 6f,
                                                      6f);
                            if (rect.Y < (panelBottom - cp.CalenderScale.Height))
                            {
                                g.FillRectangle(ls.LineBrush, rect);
                            }
                        }
                    }
                }
            }
        }

        private void paintMark(Graphics g, ChartDiv cp, MarkShape ms, float scaleX, DataRow dr)
        {
            if (!(dr[ms.Name] is DBNull) && !(dr[ms.MarkStyleField] is DBNull))
            {
                var markStyle = (MarkStyle) Enum.Parse(typeof (MarkStyle), dr[ms.MarkStyleField].ToString());
                var chartValue = Convert.ToDouble(dr[ms.Name]);
                var color = ms.DicMarkColor[markStyle];
                var path = Common.GetSignalMarkShape(scaleX, GetY(cp.PanelID, chartValue, ms), xScaleSpace,
                                                     markStyle);
                Brush brush = null;
                var pen = new Pen(color);
                if (ms.Selected)
                {
                    if (ShowCrossHair)
                    {
                        ms.Selected = false;
                    }
                    else
                    {
                        brush = new SolidBrush(color);
                    }
                }
                if (brush == null)
                {
                    brush = new SolidBrush(Color.FromArgb(100, color));
                }
                g.FillPath(brush, path);
                g.DrawPath(pen, path);
                brush.Dispose();
                pen.Dispose();
                path.Dispose();
            }
        }

        private void paintMenu(Graphics g)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;
            var allSelectedShape = GetAllSelectedShape();
            if ((allSelectedShape.Count == 1) && _allowShowShapeMenu)
            {
                var shape = allSelectedShape[0];
                var pen = new Pen(_offSetMenu.BorderColor, 1f);
                Brush brush = new SolidBrush(_offSetMenu.BgColor);
                var roundRectangle = Common.GetRoundRectangle(2, _offSetMenu.GetUpRect());
                g.FillPath(brush, roundRectangle);
                g.DrawPath(pen, roundRectangle);
                roundRectangle.Dispose();
                var pen2 = new Pen(_offSetMenu.BorderColor, 2f)
                               {
                                   EndCap = LineCap.ArrowAnchor,
                                   CustomEndCap = new AdjustableArrowCap(3f, 3f, true)
                               };
                g.DrawLine(pen2, (_offSetMenu.GetUpRect().X + 9), (_offSetMenu.GetUpRect().Bottom - 3),
                           (_offSetMenu.GetUpRect().X + 9), (_offSetMenu.GetUpRect().Y + 3));
                roundRectangle = Common.GetRoundRectangle(2, _offSetMenu.GetLeftRect());
                g.FillPath(brush, roundRectangle);
                g.DrawPath(pen, roundRectangle);
                roundRectangle.Dispose();
                pen.Width = 2f;
                g.DrawLine(pen, (_offSetMenu.GetLeftRect().X + 3), (_offSetMenu.GetLeftRect().Y + 9),
                           (_offSetMenu.GetLeftRect().X + 15), (_offSetMenu.GetLeftRect().Y + 9));
                pen.Width = 1f;
                g.FillRectangle(brush, _offSetMenu.GetMoveRect());
                g.DrawLine(pen, _offSetMenu.GetMoveRect().X + 5, _offSetMenu.GetMoveRect().Y,
                           _offSetMenu.GetMoveRect().X + 5, _offSetMenu.GetMoveRect().Bottom);
                g.DrawLine(pen, _offSetMenu.GetMoveRect().X, _offSetMenu.GetMoveRect().Y + 5,
                           _offSetMenu.GetMoveRect().Right, _offSetMenu.GetMoveRect().Y + 5);
                roundRectangle = Common.GetRoundRectangle(2, _offSetMenu.GetRightRect());
                g.FillPath(brush, roundRectangle);
                g.DrawPath(pen, roundRectangle);
                roundRectangle.Dispose();
                pen.Width = 2f;
                g.DrawLine(pen, (_offSetMenu.GetRightRect().X + 3), (_offSetMenu.GetRightRect().Y + 9),
                           (_offSetMenu.GetRightRect().X + 15), (_offSetMenu.GetRightRect().Y + 9));
                g.DrawLine(pen, (_offSetMenu.GetRightRect().X + 9), (_offSetMenu.GetRightRect().Y + 3),
                           (_offSetMenu.GetRightRect().X + 9), (_offSetMenu.GetRightRect().Y + 15));
                pen.Width = 1f;
                roundRectangle = Common.GetRoundRectangle(2, _offSetMenu.GetDownRect());
                g.FillPath(brush, roundRectangle);
                g.DrawPath(pen, roundRectangle);
                roundRectangle.Dispose();
                g.DrawLine(pen2, (_offSetMenu.GetDownRect().X + 9), (_offSetMenu.GetDownRect().Y + 3),
                           (_offSetMenu.GetDownRect().X + 9), (_offSetMenu.GetDownRect().Bottom - 3));
                roundRectangle = Common.GetRoundRectangle(2, _offSetMenu.GetRangeUpRect());
                g.FillPath(brush, roundRectangle);
                g.DrawPath(pen, roundRectangle);
                roundRectangle.Dispose();
                roundRectangle = Common.GetRoundRectangle(2, _offSetMenu.GetRangeDownRect());
                g.FillPath(brush, roundRectangle);
                g.DrawPath(pen, roundRectangle);
                roundRectangle.Dispose();
                pen2.Dispose();
                pen2 = new Pen(_offSetMenu.BorderColor, 2f);
                g.DrawLine(pen2, _offSetMenu.Locaition.X + 0x1d, _offSetMenu.GetRangeUpRect().Bottom,
                           _offSetMenu.Locaition.X + 0x1d, _offSetMenu.GetRangeDownRect().Top);
                roundRectangle = Common.GetRoundRectangle(2, _offSetMenu.GetDefaultButtonRect());
                g.FillPath(brush, roundRectangle);
                g.DrawPath(pen, roundRectangle);
                roundRectangle.Dispose();
                pen2.EndCap = LineCap.ArrowAnchor;
                pen2.CustomEndCap = new AdjustableArrowCap(3f, 3f, true);
                g.DrawBezier(pen2, (_offSetMenu.GetDefaultButtonRect().X + 8), (_offSetMenu.GetDefaultButtonRect().Y + 2),
                             (_offSetMenu.GetDefaultButtonRect().X + 2), (_offSetMenu.GetDefaultButtonRect().Y + 6),
                             (_offSetMenu.GetDefaultButtonRect().X + 4), (_offSetMenu.GetDefaultButtonRect().Y + 10),
                             (_offSetMenu.GetDefaultButtonRect().X + 8), (_offSetMenu.GetDefaultButtonRect().Y + 0x10));
                g.DrawBezier(pen2, (_offSetMenu.GetDefaultButtonRect().X + 9), (_offSetMenu.GetDefaultButtonRect().Y + 15),
                             (_offSetMenu.GetDefaultButtonRect().X + 12), (_offSetMenu.GetDefaultButtonRect().Y + 0x10),
                             (_offSetMenu.GetDefaultButtonRect().X + 0x12), (_offSetMenu.GetDefaultButtonRect().Y + 8),
                             (_offSetMenu.GetDefaultButtonRect().X + 9), (_offSetMenu.GetDefaultButtonRect().Y + 2));
                for (var i = 0f; i < _offSetMenu.RangeHeight; i += 10f)
                {
                    roundRectangle = Common.GetRoundRectangle(1,
                                                              new RectangleF(
                                                                  new PointF((_offSetMenu.Locaition.X + 0x18),
                                                                             (_offSetMenu.GetRangeUpRect().Bottom + i) +
                                                                             5f), new Size(10, 2)));
                    g.FillPath(brush, roundRectangle);
                    g.DrawPath(pen, roundRectangle);
                    roundRectangle.Dispose();
                }
                roundRectangle = Common.GetRoundRectangle(3, _offSetMenu.GetChangeRangeRect());
                g.FillPath(brush, roundRectangle);
                g.DrawPath(pen, roundRectangle);
                g.DrawString(_offSetMenu.CurStep.ToString(), new Font("New Times Roman", 8f, FontStyle.Bold), brush,
                             new Point(_offSetMenu.GetChangeRangeRect().Right + 5, _offSetMenu.GetChangeRangeRect().Y - 2));
                g.DrawString("ZORDER: " + shape.ZOrder, new Font("New Times Roman", 7f, FontStyle.Bold), brush,
                             new PointF((_offSetMenu.Locaition.X + 0x41), _offSetMenu.Locaition.Y));
                g.DrawString("OFFSET: " + shape.OffSet, new Font("New Times Roman", 7f, FontStyle.Bold), brush,
                             new PointF((_offSetMenu.Locaition.X + 0x41), (_offSetMenu.Locaition.Y + 15)));
                g.DrawString("ZOOM: " + shape.Zoom, new Font("New Times Roman", 7f, FontStyle.Bold), brush,
                             new PointF((_offSetMenu.Locaition.X + 0x41), (_offSetMenu.Locaition.Y + 30)));
                roundRectangle.Dispose();
                roundRectangle.Dispose();
                pen.Dispose();
                brush.Dispose();
                pen2.Dispose();
            }
            g.SmoothingMode = SmoothingMode.Default;
        }

        public void paintMouseScroll(Graphics g)
        {
            if (isScrollByMouse)
            {
                float x = BeginScrollPoint.X;
                float leftYScaleWidth = base.PointToClient(MousePosition).X;
                if (leftYScaleWidth < this._leftYScaleWidth)
                {
                    leftYScaleWidth = this._leftYScaleWidth;
                }
                if (leftYScaleWidth > (base.Width - _rightYScaleSpace))
                {
                    leftYScaleWidth = base.Width - _rightYScaleSpace;
                }
                foreach (var div in dicChartDiv.Values)
                {
                    Brush brush = new LinearGradientBrush(div.Rect,
                                                          Color.FromArgb(50, Common.GetReverseColor(div.BgBeginColor)),
                                                          Color.FromArgb(50, Common.GetReverseColor(div.BgEndColor)),
                                                          270f);
                    if (leftYScaleWidth > x)
                    {
                        var rect = new RectangleF(x, div.Rect.Y, leftYScaleWidth - x, div.Rect.Height);
                        g.FillRectangle(brush, rect);
                    }
                    else if (x > leftYScaleWidth)
                    {
                        var ef2 = new RectangleF(leftYScaleWidth, div.Rect.Y, x - leftYScaleWidth, div.Rect.Height);
                        g.FillRectangle(brush, ef2);
                    }
                    brush.Dispose();
                }
            }
        }

        private void paintProcessBar(Graphics g)
        {
            g.SmoothingMode = SmoothingMode.HighQuality;
            if (processBarObject.Visible)
            {
                foreach (var range in processBarObject.ColorRangeList)
                {
                    if ((processBarObject.Value < range.BeginValue) || (processBarObject.Value > range.EndValue))
                    {
                        continue;
                    }
                    var rect = new Rectangle((base.Width/2) - (processBarObject.Width/2),
                                             (base.Height/2) - (processBarObject.Height/2), processBarObject.Width,
                                             processBarObject.Height);
                    var rangeColor = range.RangeColor;
                    var builder = new StringBuilder();
                    builder.Append(range.Word + "\r\n");
                    builder.Append(processBarObject.Value + "%");
                    Brush brush = new SolidBrush(Color.FromArgb(90, rangeColor));
                    var pen = new Pen(rangeColor, 2f);
                    var num = 270;
                    var num2 =
                        Convert.ToInt32((((processBarObject.Value)/
                                          ((double) (processBarObject.Maximum - processBarObject.Minimum)))*360.0));
                    var rectangle2 = new Rectangle(rect.X, rect.Y, rect.Width - 2, rect.Height - 2);
                    if (processBarObject.Style == ProcesBar.StyleType.Round)
                    {
                        var path = new GraphicsPath();
                        path.AddPie(rect, num, num2);
                        var path2 = new GraphicsPath();
                        path2.AddEllipse(new Rectangle(rectangle2.X + 20, rectangle2.Y + 20, rectangle2.Width - 40,
                                                       rectangle2.Height - 40));
                        var region = new Region(path2);
                        var region2 = new Region(path);
                        region2.Exclude(region);
                        g.FillRegion(brush, region2);
                        g.DrawEllipse(pen, rectangle2);
                        g.DrawEllipse(pen,
                                      new Rectangle(rectangle2.X + 20, rectangle2.Y + 20, rectangle2.Width - 40,
                                                    rectangle2.Height - 40));
                        path2.Dispose();
                        path.Dispose();
                        region2.Dispose();
                        region.Dispose();
                    }
                    else
                    {
                        g.FillPie(brush, rect, num, num2);
                        if (processBarObject.Value == processBarObject.Maximum)
                        {
                            g.DrawEllipse(pen, rectangle2);
                        }
                        else
                        {
                            g.DrawPie(pen, rectangle2, num, (num2 + 1));
                        }
                    }
                    var wordFont = range.WordFont;
                    var format = new StringFormat
                                     {
                                         Alignment = StringAlignment.Center
                                     };
                    var ef = g.MeasureString(builder.ToString(), wordFont);
                    g.DrawString(builder.ToString(), wordFont, Brushes.White,
                                 new PointF((base.Width/2), (base.Height/2) - (ef.Height/2f)), format);
                    brush.Dispose();
                    pen.Dispose();
                    format.Dispose();
                    break;
                }
            }
            g.SmoothingMode = SmoothingMode.Default;
        }

        private void paintScale(Graphics g, ChartDiv cp)
        {
            var format = new StringFormat();
            var sMin = 0.0;
            var step = 0.0;
            var n = 0;
            var num4 = cp.Rect.Y + cp.Rect.Height;
            var workSpaceY = GetWorkSpaceY(cp.PanelID);
            if (cp.CalenderScale.Visible && (base.Height >= cp.CalenderScale.Height))
            {
                g.DrawLine(cp.CalenderScale.ScalePen, 0, num4 - cp.CalenderScale.Height, base.Width,
                           num4 - cp.CalenderScale.Height);
                var num6 = firstVisibleRecord - 1;
                var lastVisibleRecord = LastVisibleRecord;
                if (num6 >= 0)
                {
                    var dictionary = new Dictionary<ChartDiv, float>();
                    for (var i = num6; i < lastVisibleRecord; i++)
                    {
                        var str = dataSource.Rows[i][calenderScaleField].ToString();
                        if (dataSource.Rows[i] != null)
                        {
                            var x = GetX(i);
                            var calenderFormatTimeKey = Common.GetCalenderFormatTimeKey(str,
                                                                                        cp.CalenderScale.
                                                                                            CalenderFormat);
                            var ef = g.MeasureString(calenderFormatTimeKey, cp.CalenderScale.Font);
                            var num10 = cp.Rect.Y + cp.Rect.Height;
                            if (i == (firstVisibleRecord - 1))
                            {
                                g.DrawLine(cp.CalenderScale.ScalePen, x, (num10 - cp.CalenderScale.Height), x,
                                           ((num10 - cp.CalenderScale.Height) + 6));
                                g.DrawString(calenderFormatTimeKey, cp.CalenderScale.Font, cp.CalenderScale.Font_Brush,
                                             new PointF(x - (ef.Width/2f), ((num10 - cp.CalenderScale.Height) + 6)));
                                dictionary[cp] = x + (ef.Width/2f);
                            }
                            else if (((x - (ef.Width/2f)) - 20f) > dictionary[cp])
                            {
                                g.DrawString(calenderFormatTimeKey, cp.CalenderScale.Font, cp.CalenderScale.Font_Brush,
                                             new PointF(x - (ef.Width/2f), ((num10 - cp.CalenderScale.Height) + 6)));
                                g.DrawLine(cp.CalenderScale.ScalePen, x, (num10 - cp.CalenderScale.Height), x,
                                           ((num10 - cp.CalenderScale.Height) + 6));
                                dictionary[cp] = x + (ef.Width/2f);
                            }
                            else
                            {
                                g.DrawLine(cp.CalenderScale.ScalePen, x, (num10 - cp.CalenderScale.Height), x,
                                           ((num10 - cp.CalenderScale.Height) + 3));
                            }
                        }
                    }
                }
            }
            var flag = false;
            if ((_leftYScaleWidth != 0) && (_leftYScaleWidth <= base.Width))
            {
                if (_leftYScaleWidth <= base.Width)
                {
                    g.DrawLine(cp.LeftYScale.ScalePen, _leftYScaleWidth, cp.Rect.Y + 1, _leftYScaleWidth,
                               num4 - cp.CalenderScale.Height);
                }
                if (!lockGraph)
                {
                    var font = cp.LeftYScale.Font;
                    var ef2 = g.MeasureString(" ", font, 0x3e8, format);
                    n = (((int) ((workSpaceY)/ef2.Height))*40)/30;
                    Common.GridScale(cp.MinValue[0], cp.MaxValue[0], n, ref sMin, ref step, cp.LeftYScale.Tick);
                    var num11 = 0;
                    var gridInterval = cp.GridInterval;
                    var list = new List<double>();
                    while (sMin <= cp.MaxValue[0])
                    {
                        if (sMin > cp.MinValue[0])
                        {
                            list.Add(sMin);
                        }
                        sMin += step;
                        num11++;
                    }
                    for (var j = 0; j < list.Count; j++)
                    {
                        if (((list.Count < gridInterval) && (j == (list.Count - 1))) ||
                            ((j != 0) && (((j + 1)%gridInterval) == 0)))
                        {
                            var text = Common.GetValueByDigit(list[j], cp.LeftYScale.Digit, true);
                            ef2 = g.MeasureString(text, font, 0x3e8, format);
                            g.DrawLine(cp.LeftYScale.ScalePen, (_leftYScaleWidth - 10), GetY(cp.PanelID, list[j], null),
                                       _leftYScaleWidth, GetY(cp.PanelID, list[j], null));
                            if (cp.LeftYScale.DecimalStyle == DecimalStyle.Standard)
                            {
                                g.DrawString(text, font, cp.LeftYScale.Font_Brush,
                                             new RectangleF((_leftYScaleWidth - 10) - ef2.Width,
                                                            GetY(cp.PanelID, list[j], null) - (ef2.Height/2f), ef2.Width,
                                                            ef2.Height));
                            }
                            else if (cp.LeftYScale.DecimalStyle == DecimalStyle.UnderLine)
                            {
                                var strArray = text.Split(new[] {"."}, StringSplitOptions.RemoveEmptyEntries);
                                var ef3 = new SizeF();
                                if (strArray.Length >= 1)
                                {
                                    g.DrawString(strArray[0], font, cp.LeftYScale.Font_Brush,
                                                 ((_leftYScaleWidth - 10) - ef2.Width),
                                                 (GetY(cp.PanelID, list[j], null) - (ef2.Height/2f)));
                                }
                                if (strArray.Length >= 2)
                                {
                                    var font2 = Common.AddUnderLineToFont(font);
                                    ef3 = g.MeasureString(strArray[0], font, 0x3e8, format);
                                    g.DrawString(strArray[1], font2, cp.LeftYScale.Font_Brush,
                                                 (((_leftYScaleWidth - 10) - ef2.Width) + ef3.Width),
                                                 (GetY(cp.PanelID, list[j], null) - (ef2.Height/2f)));
                                }
                            }
                            flag = true;
                            if (cp.ShowGrid)
                            {
                                g.DrawLine(cp.Grid_Pen, _leftYScaleWidth, GetY(cp.PanelID, list[j], null),
                                           (base.Width - _rightYScaleSpace), GetY(cp.PanelID, list[j], null));
                            }
                        }
                        else
                        {
                            g.DrawLine(cp.LeftYScale.ScalePen, (_leftYScaleWidth - 5), GetY(cp.PanelID, list[j], null),
                                       _leftYScaleWidth, GetY(cp.PanelID, list[j], null));
                        }
                    }
                }
            }
            if ((_rightYScaleSpace != 0) && (_rightYScaleSpace <= base.Width))
            {
                if ((base.Width - _rightYScaleSpace) >= _leftYScaleWidth)
                {
                    g.DrawLine(cp.RightYScale.ScalePen, (base.Width - _rightYScaleSpace), (cp.Rect.Y + 1),
                               (base.Width - _rightYScaleSpace), (num4 - cp.CalenderScale.Height));
                }
                if (!lockGraph)
                {
                    var font3 = cp.RightYScale.Font;
                    var ef4 = g.MeasureString(" ", font3, 0x3e8, format);
                    n = (((int) ((workSpaceY)/ef4.Height))*40)/30;
                    Common.GridScale(cp.MinValue[0], cp.MaxValue[0], n, ref sMin, ref step, cp.RightYScale.Tick);
                    var num14 = 0;
                    var num15 = cp.GridInterval;
                    var list2 = new List<double>();
                    while (sMin <= cp.MaxValue[0])
                    {
                        if (sMin > cp.MinValue[0])
                        {
                            list2.Add(sMin);
                        }
                        sMin += step;
                        num14++;
                    }
                    for (var k = 0; k < list2.Count; k++)
                    {
                        if (((list2.Count < num15) && (k == (list2.Count - 1))) || ((k != 0) && (((k + 1)%num15) == 0)))
                        {
                            var s = Common.GetValueByDigit(list2[k], cp.RightYScale.Digit, true);
                            g.DrawLine(cp.RightYScale.ScalePen, (base.Width - _rightYScaleSpace),
                                       GetY(cp.PanelID, list2[k], null), ((base.Width - _rightYScaleSpace) + 10),
                                       GetY(cp.PanelID, list2[k], null));
                            if (cp.LeftYScale.DecimalStyle == DecimalStyle.Standard)
                            {
                                g.DrawString(s, font3, cp.RightYScale.Font_Brush, ((base.Width - _rightYScaleSpace) + 10),
                                             GetY(cp.PanelID, list2[k], null) - (ef4.Height/2f));
                            }
                            else if (cp.LeftYScale.DecimalStyle == DecimalStyle.UnderLine)
                            {
                                var strArray2 = s.Split(new[] {"."}, StringSplitOptions.RemoveEmptyEntries);
                                var ef5 = new SizeF();
                                if (strArray2.Length >= 1)
                                {
                                    g.DrawString(strArray2[0], font3, cp.RightYScale.Font_Brush,
                                                 ((base.Width - _rightYScaleSpace) + 10),
                                                 GetY(cp.PanelID, list2[k], null) - (ef4.Height/2f));
                                }
                                if (strArray2.Length >= 2)
                                {
                                    var font4 = Common.AddUnderLineToFont(font3);
                                    ef5 = g.MeasureString(strArray2[0], font3, 0x3e8, format);
                                    g.DrawString(strArray2[1], font4, cp.LeftYScale.Font_Brush,
                                                 (((base.Width - _rightYScaleSpace) + 10) + ef5.Width),
                                                 (GetY(cp.PanelID, list2[k], null) - (ef4.Height/2f)));
                                }
                            }
                            if (!flag)
                            {
                                flag = true;
                                if (cp.ShowGrid)
                                {
                                    g.DrawLine(cp.Grid_Pen, _leftYScaleWidth, GetY(cp.PanelID, list2[k], null),
                                               (base.Width - _rightYScaleSpace), GetY(cp.PanelID, list2[k], null));
                                }
                            }
                        }
                        else
                        {
                            g.DrawLine(cp.RightYScale.ScalePen, (base.Width - _rightYScaleSpace),
                                       GetY(cp.PanelID, list2[k], null), ((base.Width - _rightYScaleSpace) + 5),
                                       GetY(cp.PanelID, list2[k], null));
                        }
                    }
                }
            }
            format.Dispose();
        }

        private void paintShape(Graphics g, ChartDiv cp)
        {
            var num = firstVisibleRecord - 1;
            var lastVisibleRecord = LastVisibleRecord;
            if ((num >= 0) && (lastVisibleRecord >= 1))
            {
                var dictionary = new Dictionary<LineShape, GraphicsPath>();
                for (var i = num; i < lastVisibleRecord; i++)
                {
                    dataSource.Rows[i][calenderScaleField].ToString();
                    var dr = dataSource.Rows[i];
                    if (dr != null)
                    {
                        var x = GetX(i);
                        var panelBottom = cp.Rect.Y + cp.Rect.Height;
                        foreach (var shape in GetSortedShape(cp.PanelID, "DESC"))
                        {
                            if ((cp.MaxValue[shape.ZOrder] - cp.MinValue[shape.ZOrder]) != 0.0)
                            {
                                if (shape.ShapeType == ShapeType.Bar)
                                {
                                    var bs = shape as BarShape;
                                    paintBar(g, cp, bs, i, x, dr);
                                }
                                else
                                {
                                    if (shape.ShapeType == ShapeType.Candle)
                                    {
                                        var cs = shape as CandleShape;
                                        paintCandle(g, cp, cs, i, x, dr);
                                        continue;
                                    }
                                    if (shape.ShapeType == ShapeType.Line)
                                    {
                                        var key = shape as LineShape;
                                        if (!dictionary.ContainsKey(key))
                                        {
                                            dictionary[key] = new GraphicsPath();
                                        }
                                        paintLine(g, dictionary[key], cp, key, i, x, panelBottom, dr);
                                    }
                                }
                            }
                        }
                    }
                }
                foreach (var shape5 in dictionary.Keys)
                {
                    if (dictionary[shape5] != null)
                    {
                        g.DrawPath(shape5.LinePen, dictionary[shape5]);
                    }
                }
                g.SmoothingMode = SmoothingMode.AntiAlias;
                for (var j = num; j < lastVisibleRecord; j++)
                {
                    dataSource.Rows[j][calenderScaleField].ToString();
                    var row2 = dataSource.Rows[j];
                    if (row2 != null)
                    {
                        var scaleX = GetX(j);
                        foreach (var shape6 in cp.ShapeDic.Values)
                        {
                            if (shape6.ShapeType == ShapeType.Signal)
                            {
                                var ms = shape6 as MarkShape;
                                paintMark(g, cp, ms, scaleX, row2);
                            }
                        }
                    }
                }
                g.SmoothingMode = SmoothingMode.Default;
                foreach (var shape8 in cp.ShapeDic.Values)
                {
                    if (shape8.ShapeType != ShapeType.Candle)
                    {
                        continue;
                    }
                    var shape9 = shape8 as CandleShape;
                    if ((shape9.MaxRecord != -1) && (shape9.MinRecord != -1))
                    {
                        var row3 = dataSource.Rows[shape9.MaxRecord];
                        if (!(row3[shape9.HighField] is DBNull))
                        {
                            var chartValue = Convert.ToDouble(row3[shape9.HighField]);
                            var num9 = GetX(shape9.MaxRecord);
                            var num10 = GetY(cp.PanelID, chartValue, shape9);
                            var ef = g.MeasureString(Common.GetValueByDigit(chartValue, shape9.Digit, true), Font);
                            var point = new PointF();
                            if (num9 < (_leftYScaleWidth + ef.Width))
                            {
                                point = new PointF(num9, num10 + (ef.Height/2f));
                            }
                            else if (num9 > ((base.Width - _rightYScaleSpace) - ef.Width))
                            {
                                point = new PointF(num9 - ef.Width, num10 + (ef.Height/2f));
                            }
                            else if (num9 < (base.Width/2))
                            {
                                point = new PointF(num9 - ef.Width, num10 + (ef.Height/2f));
                            }
                            else
                            {
                                point = new PointF(num9, num10 + (ef.Height/2f));
                            }
                            g.DrawString(Common.GetValueByDigit(chartValue, shape9.Digit, true), Font, Brushes.White,
                                         point);
                            g.DrawLine(Pens.White, num9, num10, point.X + (ef.Width/2f), point.Y);
                        }
                        var row4 = dataSource.Rows[shape9.MinRecord];
                        if (!(row4[shape9.LowField] is DBNull))
                        {
                            var num11 = Convert.ToDouble(row4[shape9.LowField]);
                            var ef2 = g.MeasureString(Common.GetValueByDigit(num11, shape9.Digit, true), Font);
                            var num12 = GetX(shape9.MinRecord);
                            var num13 = GetY(cp.PanelID, num11, shape9);
                            var tf2 = new PointF();
                            if (num12 < (_leftYScaleWidth + ef2.Width))
                            {
                                tf2 = new PointF(num12, num13 - ((ef2.Height*3f)/2f));
                            }
                            else if (num12 > ((base.Width - _rightYScaleSpace) - ef2.Width))
                            {
                                tf2 = new PointF(num12 - ef2.Width, num13 - ((ef2.Height*3f)/2f));
                            }
                            else if (num12 < (base.Width/2))
                            {
                                tf2 = new PointF(num12 - ef2.Width, num13 - ((ef2.Height*3f)/2f));
                            }
                            else
                            {
                                tf2 = new PointF(num12, num13 - ((ef2.Height*3f)/2f));
                            }
                            g.DrawString(Common.GetValueByDigit(num11, shape9.Digit, true), Font, Brushes.White, tf2);
                            g.DrawLine(Pens.White, num12, num13, tf2.X + (ef2.Width/2f), tf2.Y + ef2.Height);
                        }
                    }
                }
                for (var k = num; k < lastVisibleRecord; k++)
                {
                    var timeKey = dataSource.Rows[k][calenderScaleField].ToString();
                    if (dataSource.Rows[k] != null)
                    {
                        var num15 = GetX(k);
                        var dateTimeByTimeKey = Common.GetDateTimeByTimeKey(timeKey);
                        if (cp.EventTipObj.TipDic.ContainsKey(dateTimeByTimeKey))
                        {
                            var list2 = cp.EventTipObj.TipDic[dateTimeByTimeKey];
                            if (list2.Count > 0)
                            {
                                g.SmoothingMode = SmoothingMode.AntiAlias;
                                var rect = new RectangleF(num15 - 3f, (cp.Rect.Y + cp.TitleHeight) - 6f, 6f, 6f);
                                var infoBombColor = cp.EventTipObj.InfoBombColor;
                                if (ShowCrossHair && (crossStopIndex == k))
                                {
                                    infoBombColor = cp.EventTipObj.TipBgColor;
                                }
                                var pen = new Pen(infoBombColor);
                                Brush brush = new SolidBrush(infoBombColor);
                                g.FillEllipse(brush, rect);
                                g.DrawLine(pen, num15, rect.Top - 1f, num15, rect.Bottom + 1f);
                                g.DrawLine(pen, (num15 - 4f), (rect.Top + 3f), (num15 + 4f), (rect.Top + 3f));
                                g.DrawLine(pen, (num15 - 4f), (rect.Top - 1f), (num15 + 4f), (rect.Bottom + 1f));
                                g.DrawLine(pen, (num15 - 4f), (rect.Bottom + 1f), (num15 + 4f), (rect.Top - 1f));
                                if (ShowCrossHair && (crossStopIndex == k))
                                {
                                    Brush brush2 = new SolidBrush(cp.EventTipObj.TipTextColor);
                                    var width = 0f;
                                    var num17 = 0f;
                                    for (var m = 0; m < list2.Count; m++)
                                    {
                                        var text = list2[m][0].ToString();
                                        var ef4 = g.MeasureString(text, new Font("宋体", 10f));
                                        if (m == 0)
                                        {
                                            width = ef4.Width;
                                        }
                                        else if (ef4.Width > width)
                                        {
                                            width = ef4.Width;
                                        }
                                        num17 += ef4.Height;
                                    }
                                    pen.DashStyle = DashStyle.Dash;
                                    var y = (cp.Rect.Y + cp.TitleHeight) + 5f;
                                    float num20 = _leftYScaleWidth + 2;
                                    g.FillRectangle(brush, num20, y, width - 1f, num17 - 1f);
                                    y += 2f;
                                    for (var n = 0; n < list2.Count; n++)
                                    {
                                        var str3 = list2[n][0].ToString();
                                        var ef5 = g.MeasureString(str3, new Font("宋体", 10f));
                                        g.DrawString(str3, new Font("宋体", 10f), brush2, new PointF(num20, y));
                                        y += ef5.Height;
                                    }
                                    brush2.Dispose();
                                }
                                g.SmoothingMode = SmoothingMode.Default;
                                pen.Dispose();
                                brush.Dispose();
                            }
                        }
                    }
                }
            }
        }

        private void paintTitle(Graphics g)
        {
            ObjectRectDic.Clear();
            var ef = new SizeF(15f, 16f);
            foreach (var div in dicChartDiv.Values)
            {
                float leftYScaleWidth = this._leftYScaleWidth;
                var titleFont = div.TitleFont;
                var num2 = (base.Width - _rightYScaleSpace) - 2;
                if (allowMoveShape)
                {
                    foreach (var shape in GetSortedShape(div.PanelID, "ASC"))
                    {
                        switch (shape.ShapeType)
                        {
                            case ShapeType.Candle:
                                {
                                    var shape2 = shape as CandleShape;
                                    var rect = new RectangleF(num2 - ef.Width, (div.Rect.Y + 2), ef.Width, ef.Height);
                                    if (!ShowCrossHair && shape2.Selected)
                                    {
                                        g.FillRectangle(shape2.UpLineTransparentBrush, rect);
                                        g.DrawRectangle(shape2.UpLinePen, rect.X, rect.Y, rect.Width, rect.Height);
                                    }
                                    g.DrawLine(shape2.DownLinePen, (rect.X + 4f), (rect.Y + 6f), (rect.X + 4f),
                                               (rect.Bottom - 2f));
                                    g.DrawLine(shape2.UpLinePen, (rect.X + 9f), (rect.Y + 2f), (rect.X + 9f),
                                               (rect.Bottom - 4f));
                                    g.FillRectangle(shape2.DownLineBrush,
                                                    new RectangleF(rect.X + 3f, rect.Y + 8f, 3f, 5f));
                                    g.FillRectangle(shape2.UpLineBrush, new RectangleF(rect.X + 8f, rect.Y + 4f, 3f, 5f));
                                    num2 -= ((int) ef.Width) + 2;
                                    ObjectRectDic[rect] = shape2;
                                    continue;
                                }
                            case ShapeType.Bar:
                                {
                                    var shape3 = shape as BarShape;
                                    var ef3 = new RectangleF(num2 - ef.Width, (div.Rect.Y + 2), ef.Width, ef.Height);
                                    var width = shape3.Up_Pen.Width;
                                    shape3.Up_Pen.Width = 1f;
                                    if (!ShowCrossHair && shape3.Selected)
                                    {
                                        g.FillRectangle(shape3.Up_TransparentBrush, ef3);
                                        g.DrawRectangle(shape3.Up_Pen, ef3.X, ef3.Y, ef3.Width, ef3.Height);
                                    }
                                    g.FillRectangle(shape3.Up_LineBrush, (ef3.X + 1f), (ef3.Y + 10f), 3f,
                                                    ((ef3.Bottom - ef3.Y) - 11f));
                                    g.FillRectangle(shape3.Up_LineBrush, (ef3.X + 6f), (ef3.Y + 3f), 3f,
                                                    ((ef3.Bottom - ef3.Y) - 4f));
                                    g.FillRectangle(shape3.Up_LineBrush, (ef3.X + 11f), (ef3.Y + 8f), 3f,
                                                    ((ef3.Bottom - ef3.Y) - 9f));
                                    num2 -= ((int) ef.Width) + 2;
                                    ObjectRectDic[ef3] = shape3;
                                    shape3.Up_Pen.Width = width;
                                    continue;
                                }
                            case ShapeType.Line:
                                {
                                    var shape4 = shape as LineShape;
                                    var num4 = shape4.LinePen.Width;
                                    shape4.LinePen.Width = 1f;
                                    var ef4 = new RectangleF(num2 - ef.Width, (div.Rect.Y + 2), ef.Width, ef.Height);
                                    if (!ShowCrossHair && shape4.Selected)
                                    {
                                        g.FillRectangle(shape4.TransParentLineBrush, ef4);
                                        g.DrawRectangle(shape4.LinePen, ef4.X, ef4.Y, ef4.Width, ef4.Height);
                                    }
                                    var dashStyle = shape4.LinePen.DashStyle;
                                    shape4.LinePen.DashStyle = DashStyle.Solid;
                                    g.DrawLine(shape4.LinePen, (ef4.X + 2f), (ef4.Y + 5f), (ef4.X + 12f), (ef4.Y + 1f));
                                    g.DrawLine(shape4.LinePen, (ef4.X + 2f), (ef4.Y + 10f), (ef4.X + 12f), (ef4.Y + 6f));
                                    g.DrawLine(shape4.LinePen, (ef4.X + 2f), (ef4.Y + 15f), (ef4.X + 12f), (ef4.Y + 11f));
                                    shape4.LinePen.DashStyle = dashStyle;
                                    num2 -= ((int) ef.Width) + 2;
                                    ObjectRectDic[ef4] = shape4;
                                    shape4.LinePen.Width = num4;
                                    continue;
                                }
                            case ShapeType.Signal:
                                {
                                    var shape5 = shape as MarkShape;
                                    var ef5 = new RectangleF(num2 - ef.Width, (div.Rect.Y + 2), ef.Width, ef.Height);
                                    var pen = new Pen(shape5.DicMarkColor[MarkStyle.UpArrow]);
                                    var pen2 = new Pen(shape5.DicMarkColor[MarkStyle.DownArrow]);
                                    if (!ShowCrossHair && shape5.Selected)
                                    {
                                        Brush brush =
                                            new SolidBrush(Color.FromArgb(100, shape5.DicMarkColor[MarkStyle.UpArrow]));
                                        g.FillRectangle(brush, ef5);
                                        g.DrawRectangle(pen, ef5.X, ef5.Y, ef5.Width, ef5.Height);
                                        brush.Dispose();
                                    }
                                    var x = ef5.X + 4f;
                                    var y = ef5.Y + 4f;
                                    var num7 = 6;
                                    var path = Common.GetSignalMarkShape(x, y, num7, MarkStyle.UpArrow);
                                    g.DrawPath(pen, path);
                                    path.Dispose();
                                    path = Common.GetSignalMarkShape(x + 7f, y + 9f, num7, MarkStyle.DownArrow);
                                    g.DrawPath(pen2, path);
                                    path.Dispose();
                                    pen.Dispose();
                                    pen2.Dispose();
                                    num2 -= ((int) ef.Width) + 2;
                                    ObjectRectDic[ef5] = shape5;
                                    continue;
                                }
                        }
                    }
                }
                var ef6 = g.MeasureString(" ", titleFont);
                g.DrawLine(div.Grid_Pen, this._leftYScaleWidth, (div.Rect.Y + 5) + ef6.Height,
                           (base.Width - _rightYScaleSpace), (div.Rect.Y + 5) + ef6.Height);
                if (div.UserDefinedTitle)
                {
                    var format = new StringFormat();
                    var num8 = 1;
                    var num9 = div.Rect.Y + 2;
                    for (var i = 0; i < div.TitleFieldList.Count; i++)
                    {
                        var title = div.TitleFieldList[i];
                        var targetShapeField = title.TargetShapeField;
                        var fieldColor = title.FieldColor;
                        var displayTitle = title.DisplayTitle;
                        var ef7 = g.MeasureString(displayTitle, titleFont, 0x3e8, format);
                        if ((leftYScaleWidth + ef7.Width) > num2)
                        {
                            num8++;
                            if (num8 > div.MaxTitleLine)
                            {
                                break;
                            }
                            num9 += ((int) ef7.Height) + 2;
                            leftYScaleWidth = this._leftYScaleWidth;
                            num2 = base.Width - _rightYScaleSpace;
                            if ((num9 + ((int) ef7.Height)) >= (div.Rect.Bottom - div.CalenderScale.Height))
                            {
                                break;
                            }
                        }
                        var rectangle = new Rectangle((int) leftYScaleWidth, num9, (int) ef7.Width, (int) ef7.Height);
                        var layoutRectangle = new RectangleF(leftYScaleWidth, num9, ef7.Width, ef7.Height);
                        if ((leftYScaleWidth + ef7.Width) <= num2)
                        {
                            g.DrawString(displayTitle, titleFont, title.FieldBrush, layoutRectangle);
                            if (allowMoveShape)
                            {
                                foreach (var shape6 in GetSortedShape(div.PanelID, "ASC"))
                                {
                                    if (shape6.ShapeType == ShapeType.Candle)
                                    {
                                        var shape7 = shape6 as CandleShape;
                                        if (((shape7.OpenField == targetShapeField) ||
                                             (shape7.HighField == targetShapeField)) ||
                                            ((shape7.LowField == targetShapeField) ||
                                             (shape7.CloseField == targetShapeField)))
                                        {
                                            ObjectRectDic[rectangle] = shape7;
                                        }
                                        continue;
                                    }
                                    ObjectRectDic[rectangle] = shape6;
                                }
                            }
                            leftYScaleWidth += ef7.Width;
                        }
                    }
                    format.Dispose();
                    continue;
                }
                var ef9 = g.MeasureString(div.PanelTitle, titleFont);
                if ((leftYScaleWidth + ef9.Width) <= (base.Width - _rightYScaleSpace))
                {
                    g.DrawString(div.PanelTitle, titleFont, div.TitleFont_Brush,
                                 new PointF(leftYScaleWidth, (div.Rect.Y + 2)));
                }
                leftYScaleWidth += ef9.Width;
                DataRow row = null;
                if ((dataSource.Rows.Count > 0) && ((LastVisibleRecord > 0) & !lockGraph))
                {
                    var crossStopIndex = LastVisibleRecord - 1;
                    if (ShowCrossHair && (this.crossStopIndex <= LastVisibleRecord))
                    {
                        crossStopIndex = this.crossStopIndex;
                    }
                    if ((crossStopIndex >= 0) && (crossStopIndex < dataSource.Rows.Count))
                    {
                        row = dataSource.Rows[crossStopIndex];
                    }
                    var num12 = 1;
                    var num13 = div.Rect.Y + 2;
                    foreach (DataColumn column in dataSource.Columns)
                    {
                        var columnName = column.ColumnName;
                        string displayName = null;
                        var flag = false;
                        var white = Color.White;
                        BaseShape shape8 = null;
                        foreach (var shape9 in GetSortedShape(div.PanelID, "ASC"))
                        {
                            CandleShape shape10;
                            switch (shape9.ShapeType)
                            {
                                case ShapeType.Candle:
                                    shape10 = shape9 as CandleShape;
                                    if (!shape10.DisplayTitleField)
                                    {
                                        continue;
                                    }
                                    if (!(columnName == shape10.OpenField))
                                    {
                                        break;
                                    }
                                    white = shape10.OpenTitleColor;
                                    flag = true;
                                    shape8 = shape10;
                                    displayName = shape10.DisplayName[0];
                                    goto Label_0CA0;

                                case ShapeType.Bar:
                                    {
                                        var shape11 = shape9 as BarShape;
                                        if (!(shape11.Name == columnName) || (shape11.DisplayName == null))
                                        {
                                            continue;
                                        }
                                        white = shape11.Down_lineColor;
                                        flag = true;
                                        displayName = shape11.DisplayName;
                                        shape8 = shape11;
                                        goto Label_0CA0;
                                    }
                                case ShapeType.Line:
                                    {
                                        var shape12 = shape9 as LineShape;
                                        if (!(shape12.Name == columnName) || (shape12.DisplayName == null))
                                        {
                                            continue;
                                        }
                                        white = shape12.LineColor;
                                        flag = true;
                                        displayName = shape12.DisplayName;
                                        shape8 = shape12;
                                        goto Label_0CA0;
                                    }
                                case ShapeType.Signal:
                                    {
                                        continue;
                                    }
                                default:
                                    {
                                        continue;
                                    }
                            }
                            if (columnName == shape10.HighField)
                            {
                                white = shape10.HighTitleColor;
                                displayName = shape10.DisplayName[1];
                                flag = true;
                                shape8 = shape10;
                                break;
                            }
                            if (columnName == shape10.LowField)
                            {
                                white = shape10.LowTitleColor;
                                displayName = shape10.DisplayName[2];
                                flag = true;
                                shape8 = shape10;
                                break;
                            }
                            if (columnName == shape10.CloseField)
                            {
                                white = shape10.CloseTitleColor;
                                displayName = shape10.DisplayName[3];
                                flag = true;
                                shape8 = shape10;
                                break;
                            }
                        }
                        Label_0CA0:
                        if (flag)
                        {
                            var text = columnName + " ";
                            if (displayName != null)
                            {
                                text = displayName + " ";
                                if (displayName == string.Empty)
                                {
                                    text = displayName;
                                }
                            }
                            if (((row != null) && dataSource.Columns.Contains(columnName)) &&
                                !(row[columnName] is DBNull))
                            {
                                var result = 0.0;
                                double.TryParse(row[columnName].ToString(), out result);
                                text = text + Common.GetValueByDigit(result, shape8.Digit, true);
                            }
                            var ef10 = g.MeasureString(text, titleFont);
                            if ((leftYScaleWidth + ef10.Width) > num2)
                            {
                                num12++;
                                if (num12 > div.MaxTitleLine)
                                {
                                    break;
                                }
                                num13 += ((int) ef10.Height) + 2;
                                leftYScaleWidth = this._leftYScaleWidth;
                                num2 = base.Width - _rightYScaleSpace;
                                if ((num13 + ((int) ef10.Height)) >= (div.Rect.Bottom - div.CalenderScale.Height))
                                {
                                    break;
                                }
                            }
                            if (leftYScaleWidth > num2)
                            {
                                continue;
                            }
                            Brush brush2 = new SolidBrush(white);
                            g.DrawString(text, titleFont, brush2, new PointF(leftYScaleWidth, num13));
                            if (shape8 != null)
                            {
                                var ef11 = new RectangleF(leftYScaleWidth, num13, ef10.Width, ef10.Height);
                                ObjectRectDic[ef11] = shape8;
                                if (shape8.Selected)
                                {
                                    Brush brush3 = new SolidBrush(Color.FromArgb(100, white));
                                    g.FillRectangle(brush3, ef11);
                                    brush3.Dispose();
                                }
                            }
                            leftYScaleWidth += ef10.Width;
                            brush2.Dispose();
                        }
                    }
                    continue;
                }
            }
        }

        private void paintValuePanel(Graphics g)
        {
            if (((selectState == 0) && (GetAllSelectedShape().Count == 1)) &&
                ((VpIndex > 0) && (VpIndex <= (LastVisibleRecord - 1))))
            {
                var shape = GetAllSelectedShape()[0];
                var crossHairPoint = GetCrossHairPoint();
                var digit = 2;
                var format = "yyyy-MM-dd hh:mm:ss";
                foreach (var div in dicChartDiv.Values)
                {
                    if (((crossHairPoint.Y >= div.Rect.Y) && (crossHairPoint.Y <= (div.Rect.Y + div.Rect.Height))) &&
                        (GetWorkSpaceY(div.PanelID) > 0))
                    {
                        digit = shape.Digit;
                        format = div.CalenderScale.CalenderFormat;
                    }
                }
                var row = dataSource.Rows[VpIndex];
                new Point(GetCrossHairPoint().X + 10, GetCrossHairPoint().Y);
                var text = calenderScaleField + ":" +
                           Common.GetCalenderFormatTimeKey(row[calenderScaleField].ToString(), format);
                var font = new Font("New Times Roman", 10f, FontStyle.Bold);
                var ef = g.MeasureString(text, font);
                var highValue = 0.0;
                var num3 = 0.0;
                var valueList = new List<double>();
                var builder = new StringBuilder();
                builder.Append(text + "\r\n");
                var turquoise = Color.Turquoise;
                if (shape is CandleShape)
                {
                    var shape2 = shape as CandleShape;
                    var result = 0.0;
                    double.TryParse(row[shape2.OpenField].ToString(), out result);
                    var num5 = 0.0;
                    double.TryParse(row[shape2.HighField].ToString(), out num5);
                    var num6 = 0.0;
                    double.TryParse(row[shape2.LowField].ToString(), out num6);
                    var num7 = 0.0;
                    double.TryParse(row[shape2.CloseField].ToString(), out num7);
                    var str3 = shape2.DisplayName[0] + ":" + Common.GetValueByDigit(result, digit, true);
                    builder.Append(str3 + "\r\n");
                    var ef2 = g.MeasureString(str3, font);
                    var str4 = shape2.DisplayName[1] + ":" + Common.GetValueByDigit(num5, digit, true);
                    builder.Append(str4 + "\r\n");
                    var ef3 = g.MeasureString(str4, font);
                    var str5 = shape2.DisplayName[2] + ":" + Common.GetValueByDigit(num6, digit, true);
                    builder.Append(str5 + "\r\n");
                    var ef4 = g.MeasureString(str5, font);
                    var str6 = shape2.DisplayName[3] + ":" + Common.GetValueByDigit(num7, digit, true);
                    builder.Append(str6);
                    var ef5 = g.MeasureString(str6, font);
                    valueList.AddRange(new[] {ef.Width, ef2.Width, ef3.Width, ef4.Width, (double) ef5.Width});
                    highValue = Common.GetHighValue(valueList);
                    num3 = (((ef.Height + ef2.Height) + ef3.Height) + ef4.Height) + ef5.Height;
                }
                else if (shape is BarShape)
                {
                    var shape3 = shape as BarShape;
                    var num8 = 0.0;
                    double.TryParse(row[shape3.Name].ToString(), out num8);
                    var str7 = shape3.DisplayName + ":" + Common.GetValueByDigit(num8, digit, true);
                    builder.Append(str7);
                    var ef6 = g.MeasureString(str7, font);
                    valueList.AddRange(new[] {ef.Width, (double) ef6.Width});
                    highValue = Common.GetHighValue(valueList);
                    num3 = ef.Height + ef6.Height;
                    turquoise = Color.Yellow;
                }
                else if (shape is LineShape)
                {
                    var shape4 = shape as LineShape;
                    var num9 = 0.0;
                    double.TryParse(row[shape4.Name].ToString(), out num9);
                    var str8 = (shape4.DisplayName != null)
                                   ? (shape4.DisplayName + ":" + Common.GetValueByDigit(num9, digit, true))
                                   : (shape4.Name + ":" + Common.GetValueByDigit(num9, digit, true));
                    builder.Append(str8);
                    var ef7 = g.MeasureString(str8, font);
                    valueList.AddRange(new[] {ef.Width, (double) ef7.Width});
                    highValue = Common.GetHighValue(valueList);
                    num3 = ef.Height + ef7.Height;
                    turquoise = shape4.LineColor;
                }
                else if (shape is MarkShape)
                {
                    var shape5 = shape as MarkShape;
                    if (row[shape5.MarkDescField] is DBNull)
                    {
                        return;
                    }
                    builder.Append(row[shape5.MarkDescField].ToString());
                    var ef8 = g.MeasureString(row[shape5.MarkDescField].ToString(), font);
                    valueList.AddRange(new[] {ef.Width, (double) ef8.Width});
                    highValue = Common.GetHighValue(valueList);
                    num3 = ef.Height + ef8.Height;
                    var style = (MarkStyle) Enum.Parse(typeof (MarkStyle), row[shape5.MarkStyleField].ToString());
                    turquoise = shape5.DicMarkColor[style];
                }
                highValue += 4.0;
                num3++;
                var rect = new Rectangle(GetCrossHairPoint().X + 10, GetCrossHairPoint().Y, (int) highValue, (int) num3);
                Brush brush = new SolidBrush(Color.FromArgb(100, Color.Black));
                var pen = new Pen(turquoise);
                Brush brush2 = new SolidBrush(turquoise);
                g.FillRectangle(brush, rect);
                g.DrawRectangle(pen, rect);
                g.DrawString(builder.ToString(), font, brush2,
                             new PointF((GetCrossHairPoint().X + 10), (GetCrossHairPoint().Y + 2)));
                brush.Dispose();
                pen.Dispose();
                brush2.Dispose();
            }
        }

        private void PicGraph_Paint(object sender, PaintEventArgs e)
        {
            CreateAndDrawGraph();
        }

        private void PicGraph_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            var none = ScrollType.None;
            switch (e.KeyData)
            {
                case Keys.Left:
                    none = ScrollType.ScrollLeft;
                    break;

                case Keys.Up:
                    none = ScrollType.ZoomIn;
                    break;

                case Keys.Right:
                    none = ScrollType.ScrollRight;
                    break;

                case Keys.Down:
                    none = ScrollType.ZoomOut;
                    break;
            }
            if (none != ScrollType.None)
            {
                ScrollShape(none, 1);
            }
        }

        public void RefreshGraph()
        {
            ResetSuitProperty();
            AutoResetVisibleRecord();
            SetVisibleExtremeValue();
            ResetCrossOverRecord();
            CreateAndDrawGraph();
        }

        public void RemoveAll()
        {
            ClearGraph();
            _offSetMenu = new OffSetMenu();
            dicChartDiv.Clear();
            _indList.Clear();
            dataSource.Clear();
            dataSource.Dispose();
            dataSource = new DataTable();
            calenderScaleField = string.Empty;
            CrossHairY = -1;
            xScaleSpace = 8f;
            allowMoveShape = false;
            VpIndex = -1;
            CheckVpFlag = false;
            selectState = 0;
            CreateAndDrawGraph();
        }

        public void ResetCrossOverRecord()
        {
            if (((dataSource.Rows.Count >= GetMaxVisibleRecord()) && (dataSource.Rows.Count > 0)) && ShowCrossHair)
            {
                if (crossStopIndex < (firstVisibleRecord - 1))
                {
                    crossStopIndex = firstVisibleRecord - 1;
                }
                if (crossStopIndex > (LastVisibleRecord - 1))
                {
                    crossStopIndex = LastVisibleRecord - 1;
                }
            }
            _scrollCrossFlag = true;
        }

        public void ResetSize()
        {
            var y = 0;
            foreach (var div in dicChartDiv.Values)
            {
                div.Rect = new Rectangle(0, y, base.Width, Convert.ToInt32((((div.VerticalPercent)/100.0)*base.Height)));
                y += Convert.ToInt32((((div.VerticalPercent)/100.0)*base.Height));
                if ((div.BgBrush != null) && (div.BgBrush is LinearGradientBrush))
                {
                    div.BgBrush.Dispose();
                    div.BgBrush = new LinearGradientBrush(div.Rect, div.BgBeginColor, div.BgEndColor, 90f);
                }
            }
            if ((_offSetMenu.Locaition.X > base.Width) || (_offSetMenu.Locaition.Y > base.Height))
            {
                _offSetMenu.Locaition = new Point(40, 10);
            }
        }

        public void ResetSuitProperty()
        {
            lock (dicChartDiv)
            {
                var list = new List<int>();
                var num = 0;
                foreach (var div in dicChartDiv.Values)
                {
                    var flag = true;
                    if (div.ShapeDic.Count > 0)
                    {
                        flag = false;
                    }
                    if (flag)
                    {
                        if (!div.IsMain)
                        {
                            list.Add(div.PanelID);
                        }
                    }
                    else
                    {
                        num += div.VerticalPercent;
                    }
                }
                if (list.Count > 0)
                {
                    foreach (var num2 in list)
                    {
                        dicChartDiv.Remove(num2);
                    }
                    var num3 = 1;
                    num = 100 - num;
                    var num4 = 0;
                    foreach (var div2 in dicChartDiv.Values)
                    {
                        if (num3 == dicChartDiv.Count)
                        {
                            div2.VerticalPercent = 100 - num4;
                        }
                        else
                        {
                            div2.VerticalPercent += num/dicChartDiv.Count;
                        }
                        num4 += div2.VerticalPercent;
                        num3++;
                    }
                }
                ResetYScaleField();
                ResetSize();
            }
        }

        public void ResetYScaleField()
        {
            foreach (var div in dicChartDiv.Values)
            {
                var valueList = new List<double>();
                foreach (var shape in div.ShapeDic.Values)
                {
                    if (div.YScaleField.Count == 0)
                    {
                        if (shape.ShapeType == ShapeType.Candle)
                        {
                            div.YScaleField.Add((shape as CandleShape).OpenField);
                            div.YScaleField.Add((shape as CandleShape).CloseField);
                            div.YScaleField.Add((shape as CandleShape).HighField);
                            div.YScaleField.Add((shape as CandleShape).LowField);
                        }
                        else
                        {
                            div.YScaleField.Add(shape.Name);
                        }
                        shape.ZOrder = 0;
                    }
                    valueList.Add(shape.ZOrder);
                }
                var lowValue = (int) Common.GetLowValue(valueList);
                if (lowValue > 0)
                {
                    foreach (var shape2 in div.ShapeDic.Values)
                    {
                        shape2.ZOrder -= lowValue;
                    }
                    continue;
                }
            }
        }

        public void ResizechartDiv()
        {
            if (UserResizePanel != null)
            {
                var crossHairPoint = GetCrossHairPoint();
                ChartDiv div = null;
                var flag = false;
                foreach (var div2 in dicChartDiv.Values)
                {
                    if (flag)
                    {
                        div = div2;
                        break;
                    }
                    if (div2 == UserResizePanel)
                    {
                        flag = true;
                    }
                }
                var verticalPercent = UserResizePanel.VerticalPercent;
                if (UserResizePanel.Rect.Contains(crossHairPoint))
                {
                    UserResizePanel.VerticalPercent =
                        Convert.ToInt32((((crossHairPoint.Y - UserResizePanel.Rect.Top)/((double) base.Height))*100.0));
                    if (UserResizePanel.VerticalPercent < 1)
                    {
                        UserResizePanel.VerticalPercent = 1;
                    }
                    if (div != null)
                    {
                        div.VerticalPercent += verticalPercent - UserResizePanel.VerticalPercent;
                    }
                }
                else if ((div != null) && div.Rect.Contains(crossHairPoint))
                {
                    UserResizePanel.VerticalPercent =
                        Convert.ToInt32((((crossHairPoint.Y - UserResizePanel.Rect.Top)/((double) base.Height))*100.0));
                    if (UserResizePanel.VerticalPercent >= (verticalPercent + div.VerticalPercent))
                    {
                        UserResizePanel.VerticalPercent--;
                    }
                    div.VerticalPercent = (verticalPercent + div.VerticalPercent) - UserResizePanel.VerticalPercent;
                }
                UserResizePanel = null;
                ResetSize();
                CreateAndDrawGraph();
            }
        }

        public void ScrollLeft(int step)
        {
            if (dataSource.Rows.Count > GetMaxVisibleRecord())
            {
                var num = GetMaxVisibleRecord() - (lastVisibleRecord - firstVisibleRecord);
                if (num > 1)
                {
                    firstVisibleRecord = (lastVisibleRecord - GetMaxVisibleRecord()) + 1;
                    if (firstVisibleRecord > lastVisibleRecord)
                    {
                        firstVisibleRecord = lastVisibleRecord;
                    }
                }
                else if ((firstVisibleRecord - step) >= 1)
                {
                    firstVisibleRecord -= step;
                    LastVisibleRecord -= step;
                }
                else
                {
                    LastVisibleRecord -= firstVisibleRecord;
                    firstVisibleRecord = 1;
                }
            }
            _spaceRecord = 0;
        }

        public void ScrollLeftCrossHair(int step)
        {
            var crossStopIndex = this.crossStopIndex;
            this.crossStopIndex = crossStopIndex - step;
            if (this.crossStopIndex < 0)
            {
                this.crossStopIndex = 0;
            }
            if (crossStopIndex < firstVisibleRecord)
            {
                ScrollLeft(step);
            }
        }

        public void ScrollRight(int step)
        {
            if (dataSource.Rows.Count > GetMaxVisibleRecord())
            {
                if (LastVisibleRecord < dataSource.Rows.Count)
                {
                    if ((LastVisibleRecord + step) > dataSource.Rows.Count)
                    {
                        firstVisibleRecord += dataSource.Rows.Count - LastVisibleRecord;
                        LastVisibleRecord = dataSource.Rows.Count;
                    }
                    else
                    {
                        firstVisibleRecord += step;
                        LastVisibleRecord += step;
                    }
                }
                else
                {
                    firstVisibleRecord = lastVisibleRecord - ((int) (GetMaxVisibleRecord()*0.9));
                    if (firstVisibleRecord > lastVisibleRecord)
                    {
                        firstVisibleRecord = lastVisibleRecord;
                    }
                    _spaceRecord = lastVisibleRecord;
                }
            }
        }

        public void ScrollRightCrossHair(int step)
        {
            var crossStopIndex = this.crossStopIndex;
            this.crossStopIndex = crossStopIndex + step;
            var maxVisibleRecord = GetMaxVisibleRecord();
            if ((dataSource.Rows.Count < maxVisibleRecord) && (this.crossStopIndex >= (maxVisibleRecord - 1)))
            {
                this.crossStopIndex = maxVisibleRecord - 1;
            }
            if (crossStopIndex >= (LastVisibleRecord - 1))
            {
                ScrollRight(step);
            }
        }

        public void ScrollShape(ScrollType scrollType, int limitStep)
        {
            VpIndex = -1;
            if (lockGraph)
            {
                goto Label_0158;
            }
            var firstVisibleRecord = this.firstVisibleRecord;
            var lastVisibleRecord = this.lastVisibleRecord;
            var xScaleSpace = this.xScaleSpace;
            var flag = false;
            var flag2 = false;
            switch (scrollType)
            {
                case ScrollType.ScrollLeft:
                    flag = true;
                    if (!ShowCrossHair)
                    {
                        if (limitStep > scrollStep)
                        {
                            ScrollLeft(limitStep);
                        }
                        else
                        {
                            ScrollLeft(scrollStep);
                        }
                        goto Label_00F9;
                    }
                    if (limitStep <= scrollStep)
                    {
                        ScrollLeftCrossHair(scrollStep);
                        break;
                    }
                    ScrollLeftCrossHair(limitStep);
                    break;

                case ScrollType.ScrollRight:
                    flag = true;
                    if (!ShowCrossHair)
                    {
                        if (limitStep > scrollStep)
                        {
                            ScrollRight(limitStep);
                        }
                        else
                        {
                            ScrollRight(scrollStep);
                        }
                    }
                    else
                    {
                        if (limitStep <= scrollStep)
                        {
                            ScrollRightCrossHair(scrollStep);
                        }
                        else
                        {
                            ScrollRightCrossHair(limitStep);
                        }
                        flag2 = true;
                    }
                    goto Label_00F9;

                case ScrollType.ZoomIn:
                    flag = true;
                    ZoomIn();
                    goto Label_00F9;

                case ScrollType.ZoomOut:
                    flag = true;
                    ZoomOut();
                    goto Label_00F9;

                default:
                    goto Label_00F9;
            }
            flag2 = true;
            Label_00F9:
            if (flag)
            {
                var num4 = this.firstVisibleRecord;
                var num5 = this.lastVisibleRecord;
                var num6 = this.xScaleSpace;
                CorrectVisibleRecordMistake();
                if ((firstVisibleRecord != num4) || (lastVisibleRecord != num5))
                {
                    SetVisibleExtremeValue();
                }
                ResetCrossOverRecord();
                if (flag2)
                {
                    LocateCrossHair();
                }
                if (((firstVisibleRecord == num4) && (lastVisibleRecord == num5)) && (xScaleSpace == num6))
                {
                    drawCrossHairFlag = true;
                }
                else
                {
                    CreateAndDrawGraph();
                }
            }
            Label_0158:
            if (scrollAddSpeed)
            {
                if (scrollStep < 40)
                {
                    scrollStep += 5;
                }
            }
            else
            {
                scrollStep = 1;
            }
            base.Focus();
        }

        public void SetBackColor(int panelID, Color bgBeginColor, Color bgEndColor)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                var div = dicChartDiv[panelID];
                div.BgBeginColor = bgBeginColor;
                div.BgEndColor = bgEndColor;
                if (div.BgBeginColor == div.BgEndColor)
                {
                    div.BgBrush = new SolidBrush(div.BgBeginColor);
                }
                else
                {
                    div.BgBrush = new LinearGradientBrush(div.Rect, div.BgBeginColor, div.BgEndColor, 90f);
                }
            }
        }

        public void SetBar(string name, string displayName, Color upColor, Color downColor, int width, double tick,
                           int digit, BarStyle barStyle)
        {
            foreach (var div in dicChartDiv.Values)
            {
                if (div.ShapeDic.ContainsKey(name))
                {
                    var shape = div.ShapeDic[name] as BarShape;
                    shape.DisplayName = displayName;
                    shape.BarStyle = barStyle;
                    shape.LineWidth = width;
                    shape.Up_LineColor = upColor;
                    shape.Down_lineColor = downColor;
                    shape.Tick = tick;
                    shape.Digit = digit;
                    break;
                }
            }
        }

        public void SetBarColor(string name, Color barColor, int index)
        {
            foreach (var div in dicChartDiv.Values)
            {
                if (div.ShapeDic.ContainsKey(name))
                {
                    var shape = div.ShapeDic[name] as BarShape;
                    var str =
                        string.Concat(new object[] {barColor.A, ",", barColor.R, ",", barColor.G, ",", barColor.B});
                    SetValue(shape.ColorFlag, str, index);
                    break;
                }
            }
        }

        public void SetBorder(int panelID, Color borderColor, DashStyle dashStyle, int width)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                dicChartDiv[panelID].PanelBorder_Pen.Dispose();
                dicChartDiv[panelID].PanelBorder_Pen = new Pen(borderColor, width);
                if (dashStyle != DashStyle.Custom)
                {
                    dicChartDiv[panelID].PanelBorder_Pen.DashStyle = dashStyle;
                }
            }
        }

        public void SetCalenderFormat(int panelID, string format, float interval)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                dicChartDiv[panelID].CalenderScale.CalenderFormat = format;
                dicChartDiv[panelID].CalenderScale.CalenderInterval = interval;
            }
        }

        public void SetCalenderScale(int panelID, Color scaleColor, Color fontColor, Font scaleFont, bool display)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                dicChartDiv[panelID].CalenderScale.ScalePen.Dispose();
                dicChartDiv[panelID].CalenderScale.ScalePen = new Pen(scaleColor);
                dicChartDiv[panelID].CalenderScale.Font_Brush.Dispose();
                dicChartDiv[panelID].CalenderScale.Font_Brush = new SolidBrush(fontColor);
                dicChartDiv[panelID].CalenderScale.Font = scaleFont;
                dicChartDiv[panelID].CalenderScale.Height =
                    ((int) (base.CreateGraphics().MeasureString(" ", scaleFont).Height*1.2)) + 5;
                dicChartDiv[panelID].CalenderScale.Visible = display;
                if (!display)
                {
                    dicChartDiv[panelID].CalenderScale.Height = 0;
                }
            }
        }

        public void SetCalenderScaleField(string field)
        {
            if ((calenderScaleField == null) || (calenderScaleField.Length == 0))
            {
                calenderScaleField = field;
                var column = new DataColumn(calenderScaleField);
                dataSource.Columns.Add(column);
                dataSource.PrimaryKey = new[] {column};
            }
        }

        public void SetCalenderScaleTip(int panelID, Color backColor, Color fontColor, Font tipFont)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                dicChartDiv[panelID].CalenderScale.Tip_Brush.Dispose();
                dicChartDiv[panelID].CalenderScale.Tip_Brush = new SolidBrush(backColor);
                dicChartDiv[panelID].CalenderScale.TipFont_Brush.Dispose();
                dicChartDiv[panelID].CalenderScale.TipFont_Brush = new SolidBrush(fontColor);
                dicChartDiv[panelID].CalenderScale.TipFont = tipFont;
                dicChartDiv[panelID].CalenderScale.TipFont_Pen.Color = fontColor;
            }
        }

        public void SetCandle(string candleName, Color upColor, Color downColor, Color middleUpColor,
                              Color middleDownColor, double tick, int digit, CandleStyle candleStyle, bool crossFlag)
        {
            foreach (var div in dicChartDiv.Values)
            {
                if (div.ShapeDic.ContainsKey(candleName))
                {
                    var shape = div.ShapeDic[candleName] as CandleShape;
                    shape.UpColor = upColor;
                    shape.DownColor = downColor;
                    shape.MiddleUpColor = middleUpColor;
                    shape.MiddleDownColor = middleDownColor;
                    shape.CandleStyle = candleStyle;
                    shape.Tick = tick;
                    shape.Digit = digit;
                    shape.CrossFlag = crossFlag;
                    break;
                }
            }
        }

        public void SetCandleColor(string name, Color candleColor, int index)
        {
            foreach (var div in dicChartDiv.Values)
            {
                if (div.ShapeDic.ContainsKey(name))
                {
                    var shape = div.ShapeDic[name] as CandleShape;
                    var str =
                        string.Concat(new object[]
                                          {candleColor.A, ",", candleColor.R, ",", candleColor.G, ",", candleColor.B});
                    SetValue(shape.ColorFlag, str, index);
                }
            }
        }

        public void SetCandleTitle(string candleName, string openTitle, string highTitle, string lowTitle,
                                   string closeTitle, Color openTitleColor, Color highTitleColor, Color lowTitleColor,
                                   Color closeTitleColor, bool displayTitle)
        {
            foreach (var div in dicChartDiv.Values)
            {
                if (div.ShapeDic.ContainsKey(candleName))
                {
                    var shape = div.ShapeDic[candleName] as CandleShape;
                    shape.OpenTitleColor = openTitleColor;
                    shape.HighTitleColor = highTitleColor;
                    shape.LowTitleColor = lowTitleColor;
                    shape.CloseTitleColor = closeTitleColor;
                    shape.DisplayName = new[] {openTitle, highTitle, lowTitle, closeTitle};
                    shape.DisplayTitleField = displayTitle;
                }
            }
        }

        public void SetCrossHair(int panelID, Color crossHairColor, int width)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                var div = dicChartDiv[panelID];
                div.CrossHair_Pen.Dispose();
                div.CrossHair_Pen = new Pen(crossHairColor, width);
            }
        }

        public void SetGrid(int panelID, Color gridColor, DashStyle dashStyle, bool showGrid, int width)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                dicChartDiv[panelID].Grid_Pen.Color = gridColor;
                dicChartDiv[panelID].Grid_Pen.DashStyle = dashStyle;
                dicChartDiv[panelID].ShowGrid = showGrid;
            }
        }

        public void SetGridInterval(int panelID, int interval)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                dicChartDiv[panelID].GridInterval = interval;
            }
        }

        public void SetLeftYScale(int panelID, Color scaleColor, Color fontColor, Font scaleFont, double tick, int digit,
                                  DecimalStyle decimalStyle)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                dicChartDiv[panelID].LeftYScale.ScalePen.Dispose();
                dicChartDiv[panelID].LeftYScale.ScalePen = new Pen(scaleColor);
                dicChartDiv[panelID].LeftYScale.Font_Brush.Dispose();
                dicChartDiv[panelID].LeftYScale.Font_Brush = new SolidBrush(fontColor);
                dicChartDiv[panelID].LeftYScale.Font = scaleFont;
                dicChartDiv[panelID].LeftYScale.Tick = tick;
                dicChartDiv[panelID].LeftYScale.Digit = digit;
                dicChartDiv[panelID].LeftYScale.DecimalStyle = decimalStyle;
            }
        }

        public void SetLeftYTip(int panelID, Color backColor, Color fontColor, Font tipFont)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                dicChartDiv[panelID].LeftYScale.Tip_Brush.Dispose();
                dicChartDiv[panelID].LeftYScale.Tip_Brush = new SolidBrush(backColor);
                dicChartDiv[panelID].LeftYScale.TipFont_Brush.Dispose();
                dicChartDiv[panelID].LeftYScale.TipFont_Brush = new SolidBrush(fontColor);
                dicChartDiv[panelID].LeftYScale.TipFont = tipFont;
                dicChartDiv[panelID].LeftYScale.TipFont_Pen.Color = fontColor;
            }
        }

        public void SetLine(string name, string displayName, Color lineColor, int width, double tick, int digit,
                            DashStyle dashStyle)
        {
            foreach (var div in dicChartDiv.Values)
            {
                if (div.ShapeDic.ContainsKey(name))
                {
                    var shape = div.ShapeDic[name] as LineShape;
                    shape.LineColor = lineColor;
                    shape.LinePen.Width = width;
                    shape.DisplayName = displayName;
                    shape.Digit = digit;
                    shape.Tick = tick;
                    if (dashStyle != DashStyle.Custom)
                    {
                        shape.LinePen.DashStyle = dashStyle;
                    }
                    break;
                }
            }
        }

        public void SetLineDisplayName(string name, string displayName)
        {
            foreach (var div in dicChartDiv.Values)
            {
                if (div.ShapeDic.ContainsKey(name))
                {
                    var shape = div.ShapeDic[name] as LineShape;
                    shape.DisplayName = displayName;
                    break;
                }
            }
        }

        public void SetMark(string name, MarkStyle markStyle, Color markColor)
        {
            foreach (var div in dicChartDiv.Values)
            {
                if (div.ShapeDic.ContainsKey(name))
                {
                    (div.ShapeDic[name] as MarkShape).DicMarkColor[markStyle] = markColor;
                    break;
                }
            }
        }

        public void SetMarkValue(string name, double value, MarkStyle markStyle, string desc, int index)
        {
            foreach (var div in dicChartDiv.Values)
            {
                if (div.ShapeDic.ContainsKey(name))
                {
                    var shape = div.ShapeDic[name] as MarkShape;
                    SetValue(shape.Name, value, index);
                    SetValue(shape.MarkStyleField, markStyle, index);
                    SetValue(shape.MarkDescField, desc, index);
                    break;
                }
            }
        }

        public void SetOffSetMenu(Color bgColor, Color borderColor, double minStep, double maxStep, double curStep)
        {
            _offSetMenu.BgColor = bgColor;
            _offSetMenu.BorderColor = borderColor;
            _offSetMenu.MinStep = minStep;
            _offSetMenu.MaxStep = maxStep;
            _offSetMenu.CurStep = curStep;
        }

        public void SetRightYScale(int panelID, Color scaleColor, Color fontColor, Font scaleFont, double tick,
                                   int digit, DecimalStyle decimalStyle)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                dicChartDiv[panelID].RightYScale.ScalePen.Dispose();
                dicChartDiv[panelID].RightYScale.ScalePen = new Pen(scaleColor);
                dicChartDiv[panelID].RightYScale.Font_Brush.Dispose();
                dicChartDiv[panelID].RightYScale.Font_Brush = new SolidBrush(fontColor);
                dicChartDiv[panelID].RightYScale.Font = scaleFont;
                dicChartDiv[panelID].RightYScale.Tick = tick;
                dicChartDiv[panelID].RightYScale.Digit = digit;
                dicChartDiv[panelID].RightYScale.DecimalStyle = decimalStyle;
            }
        }

        public void SetRightYTip(int panelID, Color backColor, Color fontColor, Font tipFont)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                dicChartDiv[panelID].RightYScale.Tip_Brush.Dispose();
                dicChartDiv[panelID].RightYScale.Tip_Brush = new SolidBrush(backColor);
                dicChartDiv[panelID].RightYScale.TipFont_Brush.Dispose();
                dicChartDiv[panelID].RightYScale.TipFont_Brush = new SolidBrush(fontColor);
                dicChartDiv[panelID].RightYScale.TipFont = tipFont;
                dicChartDiv[panelID].RightYScale.TipFont_Pen.Color = fontColor;
            }
        }

        public void SetTipEvent(int panelID, Color infoBombColor, Color tipBgColor, Color tipTextColor)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                var div = dicChartDiv[panelID];
                div.EventTipObj.InfoBombColor = infoBombColor;
                div.EventTipObj.TipBgColor = tipBgColor;
                div.EventTipObj.TipTextColor = tipTextColor;
            }
        }

        public void SetTipEvent(int panelID, string tipName, string tipContent, DateTime dateTime)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                var div = dicChartDiv[panelID];
                List<object[]> list = null;
                if (div.EventTipObj.TipDic.ContainsKey(dateTime))
                {
                    list = div.EventTipObj.TipDic[dateTime];
                }
                if (list == null)
                {
                    list = new List<object[]>();
                }
                list.Add(new object[] {tipName, tipContent});
                div.EventTipObj.TipDic[dateTime] = list;
            }
        }

        public void SetTitle(int panelID, string title)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                dicChartDiv[panelID].PanelTitle = title;
                dicChartDiv[panelID].TitleFont_Brush.Dispose();
                dicChartDiv[panelID].TitleFont_Brush =
                    new SolidBrush(Common.GetReverseColor(dicChartDiv[panelID].BgBeginColor));
            }
        }

        public void SetTitle(int panelID, Color titleColor, Font titleFont, int maxLine)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                dicChartDiv[panelID].TitleFont_Brush.Dispose();
                dicChartDiv[panelID].TitleFont_Brush = new SolidBrush(titleColor);
                dicChartDiv[panelID].TitleFont = titleFont;
                dicChartDiv[panelID].MaxTitleLine = maxLine;
                dicChartDiv[panelID].TitleHeight = base.CreateGraphics().MeasureString(" ", titleFont).Height + 5f;
            }
        }

        public int SetValue(string field, object value, DateTime dateTime)
        {
            return SetValue(field, value, dateTime, true);
        }

        public void SetValue(string field, object value, int index)
        {
            if (dataSource.Rows.Count >= (index + 1))
            {
                SetValue(field, value, index, false);
            }
        }

        public int SetValue(string field, object value, DateTime dateTime, bool setInd)
        {
            if (!dataSource.Columns.Contains(field))
            {
                return -1;
            }
            var timeKey = Common.GetTimeKey(dateTime);
            var row = dataSource.Rows.Find(timeKey);
            if (row != null)
            {
                row[field] = value;
            }
            else
            {
                var now = DateTime.Now;
                var flag = false;
                if (dataSource.Rows.Count > 0)
                {
                    flag = true;
                    now =
                        Common.GetDateTimeByTimeKey(
                            dataSource.Rows[dataSource.Rows.Count - 1][calenderScaleField].ToString());
                }
                row = dataSource.NewRow();
                row[calenderScaleField] = timeKey;
                row[field] = value;
                dataSource.Rows.Add(row);
                if (flag && (dateTime < now))
                {
                    var defaultView = dataSource.DefaultView;
                    defaultView.Sort = calenderScaleField + " ASC";
                    dataSource = defaultView.ToTable();
                    dataSource.PrimaryKey = new[] {dataSource.Columns[calenderScaleField]};
                }
            }
            if (setInd)
            {
                var index = dataSource.Rows.IndexOf(row);
                var flag2 = false;
                for (var i = index; i < dataSource.Rows.Count; i++)
                {
                    var row1 = dataSource.Rows[i];
                    foreach (var indicator in _indList)
                    {
                        try
                        {
                            if (indicator.Set(i, field))
                            {
                                flag2 = true;
                            }
                            continue;
                        }
                        catch
                        {
                            continue;
                        }
                    }
                    if (!flag2)
                    {
                        break;
                    }
                }
            }
            return dataSource.Rows.IndexOf(row);
        }

        public void SetValue(string field, object value, int index, bool setInd)
        {
            if ((dataSource.Rows.Count >= (index + 1)) && dataSource.Columns.Contains(field))
            {
                var row = dataSource.Rows[index];
                if (row != null)
                {
                    row[field] = value;
                    if (setInd)
                    {
                        var num = dataSource.Rows.IndexOf(row);
                        var flag = false;
                        for (var i = num; i < dataSource.Rows.Count; i++)
                        {
                            var row1 = dataSource.Rows[i];
                            foreach (var indicator in _indList)
                            {
                                if (indicator.Set(i, field))
                                {
                                    flag = true;
                                }
                            }
                            if (!flag)
                            {
                                return;
                            }
                        }
                    }
                }
            }
        }

        public void SetVisibleExtremeValue()
        {
            if (GetWorkSpaceX() > 0f)
            {
                var num = firstVisibleRecord - 1;
                var lastVisibleRecord = LastVisibleRecord;
                if ((num >= 0) && (lastVisibleRecord <= dataSource.Rows.Count))
                {
                    foreach (var div in dicChartDiv.Values)
                    {
                        var dictionary = new Dictionary<CandleShape, List<object[]>>();
                        var dictionary2 = new Dictionary<int, List<double>>();
                        if (dataSource.Rows.Count > 0)
                        {
                            for (var i = num; i < lastVisibleRecord; i++)
                            {
                                dataSource.Rows[i][calenderScaleField].ToString();
                                var row = dataSource.Rows[i];
                                foreach (var shape in div.ShapeDic.Values)
                                {
                                    if (shape.ShapeType == ShapeType.Candle)
                                    {
                                        var key = shape as CandleShape;
                                        if (((div.YScaleField.Contains(key.OpenField) ||
                                              div.YScaleField.Contains(key.HighField)) ||
                                             (div.YScaleField.Contains(key.LowField) ||
                                              div.YScaleField.Contains(key.CloseField))) &&
                                            !dictionary2.ContainsKey(key.ZOrder))
                                        {
                                            dictionary2[shape.ZOrder] = new List<double>();
                                        }
                                        if (!dictionary.ContainsKey(key))
                                        {
                                            dictionary.Add(key, new List<object[]>());
                                        }
                                        if (!(row[key.OpenField] is DBNull) && (row[key.OpenField].ToString() != ""))
                                        {
                                            var result = 0.0;
                                            double.TryParse(row[key.OpenField].ToString(), out result);
                                            dictionary[key].Add(new object[] {i, result});
                                            if (div.YScaleField.Contains(key.OpenField))
                                            {
                                                dictionary2[shape.ZOrder].Add((result + key.OffSet)*key.Zoom);
                                            }
                                        }
                                        if (!(row[key.HighField] is DBNull) && (row[key.HighField].ToString() != ""))
                                        {
                                            var num5 = 0.0;
                                            double.TryParse(row[key.HighField].ToString(), out num5);
                                            dictionary[key].Add(new object[] {i, num5});
                                            if (div.YScaleField.Contains(key.HighField))
                                            {
                                                dictionary2[shape.ZOrder].Add((num5 + key.OffSet)*key.Zoom);
                                            }
                                        }
                                        if (!(row[key.LowField] is DBNull) && (row[key.LowField].ToString() != ""))
                                        {
                                            var num6 = 0.0;
                                            double.TryParse(row[key.LowField].ToString(), out num6);
                                            dictionary[key].Add(new object[] {i, num6});
                                            if (div.YScaleField.Contains(key.LowField))
                                            {
                                                dictionary2[shape.ZOrder].Add((num6 + key.OffSet)*key.Zoom);
                                            }
                                        }
                                        if (!(row[key.CloseField] is DBNull) && (row[key.CloseField].ToString() != ""))
                                        {
                                            var num7 = 0.0;
                                            double.TryParse(row[key.CloseField].ToString(), out num7);
                                            dictionary[key].Add(new object[] {i, num7});
                                            if (div.YScaleField.Contains(key.CloseField))
                                            {
                                                dictionary2[shape.ZOrder].Add((num7 + key.OffSet)*key.Zoom);
                                            }
                                        }
                                        continue;
                                    }
                                    if (div.YScaleField.Contains(shape.Name))
                                    {
                                        if (!dictionary2.ContainsKey(shape.ZOrder))
                                        {
                                            dictionary2[shape.ZOrder] = new List<double>();
                                        }
                                        if (!(row[shape.Name] is DBNull) && (row[shape.Name].ToString() != ""))
                                        {
                                            var num8 = 0.0;
                                            double.TryParse(row[shape.Name].ToString(), out num8);
                                            dictionary2[shape.ZOrder].Add((num8 + shape.OffSet)*shape.Zoom);
                                            if (shape.ShapeType != ShapeType.Bar)
                                            {
                                                continue;
                                            }
                                            dictionary2[shape.ZOrder].Add((0.0 + shape.OffSet)*shape.Zoom);
                                        }
                                    }
                                }
                            }
                        }
                        div.MaxValue.Clear();
                        div.MinValue.Clear();
                        if (dictionary2.Count > 0)
                        {
                            foreach (var num9 in dictionary2.Keys)
                            {
                                div.MaxValue[num9] = Common.GetHighValue(dictionary2[num9]);
                                div.MinValue[num9] = Common.GetLowValue(dictionary2[num9]);
                            }
                        }
                        else
                        {
                            div.MaxValue[0] = 0.0;
                            div.MinValue[0] = 0.0;
                        }
                        foreach (var shape3 in dictionary.Keys)
                        {
                            shape3.MaxRecord = Common.GetHighRecord(dictionary[shape3]);
                            shape3.MinRecord = Common.GetLoweRecord(dictionary[shape3]);
                        }
                    }
                }
            }
        }

        public void SetYScaleField(int panelID, string[] field)
        {
            if (dicChartDiv.ContainsKey(panelID))
            {
                var div = dicChartDiv[panelID];
                div.YScaleField.Clear();
                foreach (var str in field)
                {
                    div.YScaleField.Add(str);
                }
            }
        }

        public void SetYScaleSpace(int leftSpace, int rightSpace)
        {
            _leftYScaleWidth = leftSpace;
            _rightYScaleSpace = rightSpace;
        }

        public void ShowValuePanel()
        {
            if (GetAllSelectedShape().Count > 0)
            {
                var mouseOverIndex = GetMouseOverIndex();
                var shape = JudgeSelectShape(mouseOverIndex, GetCrossHairPoint().Y, 0, true);
                if ((shape != null) && (shape == GetAllSelectedShape()[0]))
                {
                    VpIndex = mouseOverIndex;
                    drawValuePanelFlag = true;
                }
            }
        }

        public void ZoomIn()
        {
            if (xScaleSpace < 50f)
            {
                var maxVisibleRecord = GetMaxVisibleRecord();
                var flag = false;
                if (dataSource.Rows.Count < maxVisibleRecord)
                {
                    flag = true;
                }
                var num2 = -1;
                if (_zoomType == 0)
                {
                    num2 = (int) (maxVisibleRecord*0.7);
                    xScaleSpace = GetWorkSpaceX()/(num2);
                }
                else if (_zoomType == 1)
                {
                    xScaleSpace++;
                    num2 = GetMaxVisibleRecord();
                }
                if (dataSource.Rows.Count >= num2)
                {
                    if (flag)
                    {
                        firstVisibleRecord = 1;
                        LastVisibleRecord = num2;
                    }
                    else
                    {
                        firstVisibleRecord = (LastVisibleRecord - num2) + 1;
                        if (firstVisibleRecord < 1)
                        {
                            firstVisibleRecord = 1;
                        }
                    }
                }
            }
        }

        public void ZoomOut()
        {
            if (xScaleSpace > 1f)
            {
                var maxVisibleRecord = GetMaxVisibleRecord();
                var num2 = -1;
                if (_zoomType == 0)
                {
                    num2 = (int) (maxVisibleRecord*1.3);
                    xScaleSpace = GetWorkSpaceX()/(num2);
                }
                else if (_zoomType == 1)
                {
                    xScaleSpace--;
                    num2 = GetMaxVisibleRecord();
                }
                if (num2 >= dataSource.Rows.Count)
                {
                    firstVisibleRecord = 1;
                    LastVisibleRecord = dataSource.Rows.Count;
                }
                else
                {
                    firstVisibleRecord = (LastVisibleRecord - num2) + 1;
                    if (firstVisibleRecord < 1)
                    {
                        firstVisibleRecord = 1;
                    }
                }
            }
        }

        #region Nested type: DrawGraphDelegate

        protected delegate void DrawGraphDelegate();

        #endregion
    }
}